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 |
|
svicky9
Posting Yak Master
232 Posts |
Posted - 2006-10-27 : 06:05:47
|
| Hi Friends I am trying to create the following procedure for updating a col for a particular tableThe procedure is as follows:create procedure vic_ltrim@col_name varchar(100),@table_name varchare(100)as update @table_name set @col_name = ltrim(@col_name)I get the error asServer: Msg 137, Level 15, State 2, Procedure vic_ltrim, Line 8Must declare the variable '@table_name'.Should i change the Data Type of the Table name??? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 06:10:19
|
| Does noone no longer design proper databases?set @sqlcmd = 'update [' + @table_name + '] set [' + @col_name + '] = ltrim(@col_name)'exec (@sqlcmd)http://www.sommarskog.se/dynamic_sql.htmlPeter LarssonHelsingborg, Sweden |
 |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2006-10-27 : 07:40:35
|
| hi Peso,can u tell me, why we can't pass table name runtime. i have just checked that, we can pass column name at runtime. why SQL server does not support this?Mahesh |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-27 : 07:52:14
|
| >> why we can't pass table name runtime. It is possible with Dynamic SQLRead that link fullyMadhivananFailing to plan is Planning to fail |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-10-27 : 09:15:49
|
| It's not about whether it is possible or not, its about why you want to do it this way...If you are forced to do this by design, it's sign of bad design !Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
|
|
|