Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie question on SCOPE_IDENTITY
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01196646
Message ID:
01196682
Vues:
9
>
>From BOL:
>
>Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.
>
>

>
>Every SQLEXEC() is different batch, so you can't use SCOPE_IDENTITY() in separate SQLEXEC(). If you want to use it you must embed it in the same SQLEXEC() with INSERT:
>
>TEXT TO lcInsert NOSHOW TEXTMERGE
>     INSERT INTO ............
>     SELECT SCOPE_IDENTITY()
>ENDTEXT
>SQLEXEC(..., lcInsert, [crsIDColumn])
>SELECT crsIDColumn
>BROWSE NORMAL
>
>But keep in mind that if you have more than one record inserted that query will return you the LAST IDENTITY value inserted.

Borislav,

Thank you very much for your help. But when I tried to use your code (almost without any changes on my part), the cursor crsIdColumn is not created. That is, I get error on line SELECT crsIdColumn.

What do you think could be the reason for it?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform