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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Set statement Using a variable

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-23 : 09:05:58
John Niemiec writes "Can I build a variable and then use that variable on the SET statement in the UPDATE portion of this query? That seems to be the issue, bu is there a work around.


DECLARE @COUNTER INTEGER
DECLARE @SETSTRING_1 CHAR(30)

SET @COUNTER = 1
SET @SETSTRING_1 = '#BILLING.M' + (CONVERT(CHAR(2),@COUNTER)) + '= #TEMP2.CHARGE'

UPDATE #BILLING
SET @SETSTRING_1
FROM #BILLING, #TEMP1
WHERE (#BILLING + '.' + 'CLIENT') = (#TEMP1 + '.' + 'CLIENT') AND
(#TEMP1 + '.' + 'MONTH') = ('M' + (CONVERT(CHAR(2),@COUNTER)))"

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-04-23 : 09:12:24
Naw. You can't do that. Either explicitly type out all of your update statement, or dynamically build the entire statement into a varchar and exec(@mySQLStatement). If you go with the latter, you will probably have trouble with scope with your temp tables.

<O>
Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-04-23 : 09:14:20
Read these Articles on Dynamic Sql by our Merkin(Yak Dynamo)

http://www.sqlteam.com/item.asp?ItemID=4599
http://www.sqlteam.com/item.asp?ItemID=4619



--------------------------------------------------------------
Go to Top of Page
   

- Advertisement -