Re: SCOPE_IDENTITY() returns NULL
From: avnrao (avn_at_newsgroups.com)
Date: 11/15/04
- Next message: Amin Sobati: "Re: find bound cols to a rule**"
- Previous message: avnrao: "Re: Lock information"
- In reply to: Tumurbaatar S.: "SCOPE_IDENTITY() returns NULL"
- Next in thread: Tumurbaatar S.: "Re: SCOPE_IDENTITY() returns NULL"
- Reply: Tumurbaatar S.: "Re: SCOPE_IDENTITY() returns NULL"
- Messages sorted by: [ date ] [ thread ]
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
>
>
- Next message: Amin Sobati: "Re: find bound cols to a rule**"
- Previous message: avnrao: "Re: Lock information"
- In reply to: Tumurbaatar S.: "SCOPE_IDENTITY() returns NULL"
- Next in thread: Tumurbaatar S.: "Re: SCOPE_IDENTITY() returns NULL"
- Reply: Tumurbaatar S.: "Re: SCOPE_IDENTITY() returns NULL"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|