Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 652
  • Last Modified:

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?
0
cossy74
Asked:
cossy74
  • 2
3 Solutions
 
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

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now