On 10/17/2012 4:23 PM, Stephen Russell wrote:
On Wed, Oct 17, 2012 at 2:51 PM, MB Software Solutions, LLC
<[email protected]> wrote:
I insert a row into a table whose PK is a GUID that's automatically
generated.  How do I get that GUID value afterwards?  I thought it would be
SELECT @@IDENTITY but that just returns NULL and I can see on a SELECT *
FROM MyTABLE that it's not a null value.
-------------

Are they two separate statements?  Or do you append the Select
@@IDENTITY after the insert text so it acts as one COMPOUND statement?

If they are separate it will not have anything to show you. If you did
numerous ones SELECT @@IDENTITY would only give you the greatest, or
the last?


That's what I'm looking for...the last row I inserted/created. In pseudo-code, I'm trying to do this:

insert into ParentTable (fields) values (values);
@PK = Get_Last_Key_Created();
insert into ChildTable (myFKToParent, otherfields) values (@PK, othervalues);

Make sense? I'm trying to quickly create stub/test data in parent AND child tables.


--
Mike Babcock, MCP
MB Software Solutions, LLC
President, Chief Software Architect
http://mbsoftwaresolutions.com
http://fabmate.com
http://twitter.com/mbabcock16

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to