Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic SQL query in a cursor
Message
From
15/03/2001 22:35:46
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00485420
Message ID:
00485712
Views:
11
I think that should work. Why, did you have a problem with it?

I think you have to close the cursor before you can deallocate it.

BOb

>On SQL 2000 ...
>
>In a Stored Proc ...
>
>Can I declare a cursor using a syntax like this:
>
CREATE PROCEDURE SP_Calcul_Rendement
>	(@NomTable 	  varchar(30),
>	 @NomChamp	  varchar(30))
>AS
>
>	DECLARE @Annee	 	smallint,
>		@Mois		smallint,
>		@Rendement	real,
>		@Cumule 	real,
>        	@Annuel 	real,
>        	@Annualise 	real
>
>	DECLARE ms_crs_1 CURSOR local static for
>			SELECT Annee, Mois, @NomChamp ,
>        			 @NomChamp + 'Cum ',
>        			 @NomChamp + 'Ann ',
>        			 @NomChamp + 'Annuel '
>             		 FROM   @NomTable
>             		 WHERE   @NomChamp  <> 0
>             		 ORDER BY Annee, Mois
>
>	open ms_crs_1
>	fetch ms_crs_1 into @Annee,
>			    @Mois,
>			    @Rendement,
>			    @Cumule,
>        		    @Annualise,
>        		    @Annuel
>
>	while @@fetch_status >= 0
>	begin
>
>		-- index suivant
>		fetch ms_crs_1 into @Annee,
>				    @Mois,
>				    @Rendement,
>				    @Cumule,
>	        		    @Annualise,
>	        		    @Annuel
>
>	end
>	deallocate ms_crs_1
>
>return (0) -- fin de SP_Calcul_Rendement
>
Previous
Reply
Map
View

Click here to load this message in the networking platform