Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic SQL query in a cursor
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00485420
Message ID:
00485799
Vues:
8
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform