Wednesday, March 7, 2012

Newbie - What is the CLR Keyword/Method for @@IDENTITY - thanks!

What is the CLR Keyword/Method for @.@.IDENTITY? I'm doing some master detail inserts and when doing the insert for the child records, i need the new key that was generated for the parent records. Thanks!
Think I may have found the answer at the following site,

http://davidhayden.com/blog/dave/archive/2006/02/16/2803.aspx

It basically says that on your insert statement to append the following statement onto the end of the insert statement:

"SET @.MyParameter = SCOPE_IDENTITY()"


And then on your command object to pass in a parameter with the name of @.MyParameter (with Direction set to output) and then access the parameter after executing the command. Haven't tried it yet but hopefully it works. Is this correct as far you guys know? Is there a better way, lemme know, thanks!

No comments:

Post a Comment