GUID and last inserted row.


i have a table with a uniqueidentifier(GUID) set to auto assign as it's primary key.
I would like to know the sql query that i can run after an insert statment to get the last row i just inserted?
Who is Participating?
Aneesh RetnakaranDatabase AdministratorCommented:
try this way

declare @Guid uniqueIdentifier
INSERT INTO urTable (UNID,  ... )
SELECT @Guid, ..
cossy74Author Commented:
aneeshattingal: I dynamically create a SqlCommand and execute it. I therefore do not think i can use your solution as i am not  using a stored procedure.
Aneesh RetnakaranDatabase AdministratorCommented:
you need to proceed in this way, otherwise you can do a select query with all the inserted values in the where part
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I have to agree with aneeshattingal, you need to use NEWID() function explicitely, otherwise you have no way to get the value.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.