GUID and last inserted row.

Hi,

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?
cossy74Asked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
try this way

declare @Guid uniqueIdentifier
SELECT @Guid= NEWID()
INSERT INTO urTable (UNID,  ... )
SELECT @Guid, ..
0
 
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.
0
 
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
0
 
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.
0
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.