Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie question on SCOPE_IDENTITY
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01196646
Message ID:
01196682
Views:
10
>
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform