Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
karthikeyan.marlen
Starting Member
16 Posts |
Posted - 2011-09-21 : 06:18:59
|
hii tried a task of inserting records to a table dynamically using stored procedureas follows create procedure proc2 (@tabl varchar(20),@sno int,@name varchar(30),@age int)asbegindeclare @qry varchar(max);set @qry='insert into ' + @tabl + ' values (sno,name,age) ( '+@sno+', '''+ @name +''','+ @age +')';exec (@qry);endbut it shows error as 'Msg 245, Level 16, State 1, Procedure proc2, Line 5Conversion failed when converting the varchar value 'insert into demo values (sno,name,age) ( ' to data type int.'so please clear me regarding thisThankskarthikeyan |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-21 : 06:23:40
|
[code]create procedure proc2 (@tabl varchar(20),@sno int,@name varchar(30),@age int)asbegindeclare @qry varchar(max);set @qry='insert into ' + @tabl + ' values (sno,name,age) ( '+ cast(@sno as varchar(20))+', '''+ @name +''','+ cast(@age as varchar(5)) +')';exec (@qry);end[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|