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 |
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2009-07-27 : 23:13:23
|
am trying to pass the table name into store procedure, when i use inside the procedure for inserting record. it trough's error.create procedure sampleproc@tablename varchar(25)asinsert into @tablename values('name','address') how to solve it?thanksby subha |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-27 : 23:23:44
|
why do you want to do this ?The only way to solve is via the Dynamic SQL way. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2009-07-27 : 23:28:14
|
| i want to update records from single table to many table based on the name and place.i thought that if common procedure accepts the table name. the process of check and inserting all will done by calling it repeatedly.that's why. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-07-28 : 02:33:50
|
quote: Originally posted by subhaoviya i want to update records from single table to many table based on the name and place.i thought that if common procedure accepts the table name. the process of check and inserting all will done by calling it repeatedly.that's why.
Hi Subetha,Your requirement is clear you can dynamical handle the Table, So u must use Dynamic SQL as khtan says.Its simple,Declare @sql varchar(8000)@sql='insert into '+ @tablename +'" values('name','address')"'Exec(@sql)Here The query is build Dynamically, and get executedSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-28 : 03:10:12
|
quote: Originally posted by senthil_nagore
quote: Originally posted by subhaoviya i want to update records from single table to many table based on the name and place.i thought that if common procedure accepts the table name. the process of check and inserting all will done by calling it repeatedly.that's why.
Hi Subetha,Your requirement is clear you can dynamical handle the Table, So u must use Dynamic SQL as khtan says.Its simple,Declare @sql varchar(8000)@sql='insert into '+ @tablename +'" values('name','address')"'Exec(@sql)Here The query is build Dynamically, and get executedSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
It should beset @sql='insert into '+ @tablename +' values(''name'',''address'')'MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|
|