Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to concate strings for column names in UPDATE statment

Status
Not open for further replies.

joblue

Programmer
Jun 21, 2000
2
0
0
SG
Is it possible to have this in an UPDATE statement?<br><br>UPDATE table SET @str1+@str2 = '001'<br><br>I got the result of &quot;1 row affected&quot; <br>But when I try to select that column, it wasn't updated.<br>The result remains NULL.<br><br>Thank you.
 
I should've taken more notice of your subject.<br><br>I don't have access to SQL server to tell you what you're doing wrong but I can offer this:<br><br>Try<br><br>DECLARE @Command VARCHAR(100)<br>SET @Command = 'UPDATE table SET ' + @str1 + @str2 + ' = &quot;001&quot;'<br>EXEC (@Command)
 
Invicta.<br><br>I quote an example.<br><br>declare @str1 = 'First'<br>declare @str2 = 'Name'<br>declare @command varchar(100)<br><br>I need it to update the column name
 
I'm still unsure of what you're trying to achieve.<br><br>The final comment in your last message seems to imply that you're trying to change the name of a column in a table.&nbsp;&nbsp;If this is the case then I'm unaware of any way of doing this other than rebuilding the table.<br><br>If you're trying to catenate two variables to make up the name of a column for subsequent update then my previous example gives the code to do that.<br><br><br>Maybe if you show me more code I'll get a better grasp?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top