Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
@Var Data fromTemp Table
Message
From
17/09/2003 13:34:22
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
@Var Data fromTemp Table
Miscellaneous
Thread ID:
00829985
Message ID:
00829985
Views:
66
I have a situation in which I have to programmatically generate a global temporary table name. Into the global temporary table with the programmatically generated name, an agregate value (SUM()) is then stored using sp_executesql. I then have to extract that value from the global temp table into an @Var for use in calculations. The usual syntax I would use is:
SELECT @Var = cnt from ##GlobalTempTable
However, this syntax will not work since I don't know the tamp table name at design time and the above syntax will not deposit the data into a local variable when run using sp_executesql.

If I could get the value directly it would be better but it's the same problem with the above syntax when trying to get the data into a local variable. I would prefer to do something like:
SET @Stmt = 'SELECT @Var = SUM([' + LTRIM( RTRIM( @Speaker ) ) + ']) FROM N=MyTable WHERE [ResponseValue] <> 9999'
exec sp_executesql @Stmt
But this does not deposit the value in a local @Var and the column name (@Speaker) is not known until run time necessitating the use of sp_executesql.

Is there a way to get around this and get the value of the agregate SUM() into a local variable when the column name is not known at design time?

Thanks,
Bill
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Next
Reply
Map
View

Click here to load this message in the networking platform