Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable
Message
 
À
08/10/2008 00:35:13
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01353548
Message ID:
01353571
Vues:
11
>Is there a way to declare a public variable in SQL2005
>
>I'm storing some formulas in a table to calculate provions, some of these formulas contains variables (i.e. @Var1, @var2, ...), I'm excuting these formulas in a stored procedure as follows
>
>set @cmd='FormulaToExecute'
>exec (@cmd)
>
>System is generating an error against every variable used inm the formula expression (Must declare the scalar variable "@Var1")


Victoria,

There is no concept of PUBLIC variables in T-SQL. Variables declared within Function, Stored Procedure or Batch have LOCAL scope, i.e. not visible from outside that code.

Maybe you should consider sending @Var1 and @Var2 as parameters to the stored procedure. Since you are using dynamic sql you should use SP_EXECUTESQL instead of EXECUTE in order to pass parameters to calling stored procedure.

Another alternative would be to store the values into GLOBAL Temporary table (prefix global temporary table names with a double number sign ##table_name) and query that table from the SP.


Regards,

Zoran
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform