January 31, 2013 at 5:32 am
Hi friends i have a small doubt in sql server plese tell me how to solve this issuse
this procedure for load records into employee table useing 3 input parameters. and
emplyoee table contains coloumns name-- id int ,name varchar(500), doj datetime
create procedure sample ( @a int,@b varchar(500),@c datetime)
as
begin
insert into employee (id,name,doj)values(@a,@b,@c)
end
and to execuete this procedure useing exec dbo.sample 10,'rad','2012-01-01'
that time procedure execute successfully load one record in employee table.
but when ever i try to load records like exec 'rsd','2013-12-10',1200 that time its given errore.
but i want load how we resolve this issuse.
January 31, 2013 at 6:35 am
The second example you're passing a string to an integer value. You can't do that. 2 does not equal 'rsv'.
On a side note, naming variables @1, @2 or @a, @b-2, is really, really, really an awful way to code. If the value represents the column Id, then name it, @Id. Clarity in coding is your best friend.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
January 31, 2013 at 6:46 am
Also, if you don't specify the parameters it is assumed that the values are being passed in using the order that the parameters are defined. In this case your procedure is expecting an INT, a STRING, and then a DATETIME value.
January 31, 2013 at 6:50 am
Great catch Lynn. Good point. But, once again, back to clarity.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply