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 |
jhnegrao
Yak Posting Veteran
81 Posts |
Posted - 2006-10-25 : 07:11:03
|
Hello, All!I'm trying to update a specific table named Requests, it' s a dinamic table, So I cannot use the name of the columns directly in a Update statement. I need to get this information and create the update statement in the moment of the transaction.Is it possible? My query is in a Stored Procedure.I want something like that.Update <Table> SET @variable = 'NomedoCliente' WHERE ......conditionsIf anybody knows, I would be great.ThanksJuliano Horta |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-25 : 07:29:28
|
I think you are stuck with your dynamic SQL solution.SET @sqlcmd = 'UPDATE ' + @MyTable + ' SET ' + @MyColumn + ' = ''NomedoCliente WHERE ' + conditions.....Peter LarssonHelsingborg, Sweden |
 |
|
jhnegrao
Yak Posting Veteran
81 Posts |
Posted - 2006-10-25 : 08:18:16
|
Hi, Peso!Thank you very much for your answer. It was soo good.How can I execute it after putting it to a variable?I need to execute this update.ThanksJuliano Hortaquote: Originally posted by Peso I think you are stuck with your dynamic SQL solution.SET @sqlcmd = 'UPDATE ' + @MyTable + ' SET ' + @MyColumn + ' = ''NomedoCliente WHERE ' + conditions.....Peter LarssonHelsingborg, Sweden
|
 |
|
mr_mist
Grunnio
1870 Posts |
Posted - 2006-10-25 : 08:20:32
|
exec @sqlcmdor use sp_executesql-------Moo. :) |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-25 : 08:20:38
|
http://www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-25 : 08:37:29
|
SET @sqlcmd = 'UPDATE [' + @MyTable + '] SET [' + @MyColumn + '] = ''NomedoCliente'' WHERE conditions.....'exec (@sqlcmd)Peter LarssonHelsingborg, Sweden |
 |
|
jhnegrao
Yak Posting Veteran
81 Posts |
Posted - 2006-10-25 : 09:06:58
|
Hello, everybody!Thank you very much. All answers was important for me.Now, My query is executing properly.Have a nice dayJuliano Horta |
 |
|
|
|
|