Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
@Var Data fromTemp Table
Message
De
17/09/2003 13:34:22
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
@Var Data fromTemp Table
Divers
Thread ID:
00829985
Message ID:
00829985
Vues:
68
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.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform