Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic SQL query in a cursor
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00485420
Message ID:
00485799
Views:
9
>Normally, SQL Server doesn't let you parameterize the FROM clause of a query. I've not seen anything that says that the behavior changes within a CURSOR and I've not explicitly tried it either. If SQL Server is complaining about it, then it probably doesn't work.

The parser was complaining about @NomTable.

I have changed my declaration to :
EXEC(' DECLARE ms_crs_1 CURSOR GLOBAL static FOR 
            SELECT Annee, Mois, ' + @NomChamp + ',  
                    ' + @NomChamp +  'Cum ' +  ',
                    ' + @NomChamp + 'Ann ' +  ',
                    ' +  @NomChamp +  'Annuel'  +  ' 
                     FROM  ' + @NomTable + '
                     WHERE ' +  @NomChamp + ' <> 0  
                     ORDER BY Annee, Mois')
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform