Re: SCOPE_IDENTITY() returns NULL

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: avnrao (avn_at_newsgroups.com)
Date: 11/15/04


Date: Mon, 15 Nov 2004 17:40:05 +0530

you have to capture SCOPE_IDENTITY() just after the insert statement and
place it into a local variable.
can you post your code??

Av.
http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet

"Tumurbaatar S." <nospam_tumurbaatar@datacom.mn> wrote in message
news:#MyygrwyEHA.4044@TK2MSFTNGP10.phx.gbl...
> My program executes INSERT on a table with an identity column and
> SELECTs back a new record id with "SELECT SCOPE_IDENTITY()".
> This works without an error. After it, the program inserts a new record
> into a detail table using the id value obtained in the previous step.
> All above INSERTs are executing within one explicit transaction.
> But SQL raises an exception that NULL value was sent for id.
> I've traced my program and found that SCOPE_IDENTITY() really
> returns NULL.
> In the BOL I found this:
>
> ...SCOPE_IDENTITY() will return the IDENTITY value inserted in T1, which
was
> the last INSERT that occurred in the same scope. The SCOPE_IDENTITY()
> function will return the NULL value if the function is invoked before any
> insert statements into an identity column occur in the scope.
>
> That is not clear for me. Anybody can explain this?
> Thank you
>
>



Relevant Pages

  • SCOPE_IDENTITY() returns NULL
    ... My program executes INSERT on a table with an identity column and ... In the BOL I found this: ... insert statements into an identity column occur in the scope. ...
    (microsoft.public.sqlserver.programming)
  • Re: Custom URL Protocols... capture output from program
    ... The program executes ... Is there any way to capture the output of this program as text and put it ... the browser? ... Assuming you mean Internet Explorer, then I believe you would have to set an ...
    (microsoft.public.win32.programmer.tools)