Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cursor variables in SP
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00833426
Message ID:
00833433
Vues:
25
The variable @empno gets evaluated at the time of DECLARE CURSOR. It should be
SET @EMPNO = 1234
DECLARE C_TOTO CURSOR FOR
SELECT salary
  FROM EMPLOYE
 WHERE EMPNO = @empno
...
>I have the following cursor (simple example here) declaration at the top of my SP:
>
>DECLARE @empno int, @salary bigint ;-)
>
>DECLARE C_TOTO CURSOR FOR
>SELECT salary
>  FROM EMPLOYE
> WHERE EMPNO = @empno
>
>
>BEGIN
>    SET @EMPNO = 1234
>    OPEN C_TOTO
>    FETCH NEXT FROM C_TOTO INTO @salary
>    CLOSE C_TOTO
>
>    SET @EMPNO = 5678
>    FETCH NEXT FROM C_TOTO INTO @salary
>    CLOSE C_TOTO
>
>    DEALLOCATE C_TOTO
>END
>
>The problem I ran into is that C_TOTO does not return any rows as if the value of @empno was null.
>
>I want to have a variable driven cursor that takes the value of @empno that changes...
>
>My question: When is @empno evaluated for the cursor definition ?
>
>
>Thanks!
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform