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 |
|
rohan_man
Starting Member
8 Posts |
Posted - 2007-06-20 : 03:21:38
|
| Hi,Does anyone know if it's possible to pass the table name to a stored procedure so that it can update a value in the table named.I need to have one stored procedure which will update data in any table.If I have stored procedure called UpdateTable, which takes 5 parameters @TableName, @PrimaryKeyName, @PrimaryKeyValue, @ColumnName, @ColumnValueThen I would have something likeUPDATE @TableNameSet @ColumnName = @ColumnValueWhere @PrimaryKeyName = @PrimaryKeyValueCheersRohan |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-06-20 : 03:27:53
|
| Have a look at dynamic sql.Also search for articles on why this is a really bad idea.it would beexec ('UPDATE [' + @TableName + ']Set [' + @ColumnName + '] = ''' + @ColumnValue + 'Where [' + @PrimaryKeyName + '] = ''' + @PrimaryKeyValue + '''')==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
rohan_man
Starting Member
8 Posts |
Posted - 2007-06-20 : 18:36:33
|
| Thanks for those replies.That link is very useful and explains exactly what I needed to knowCheersRohan |
 |
|
|
|
|
|