views:

62

answers:

1

Hi all,

I am using output inserted.PKfielName to get the varchar type primary key value of last inserted record. Now i want to get the primary key value of last updated record.

Geetha

+1  A: 

You just use the INSERTED clause again, such as in this example:

CREATE TABLE #test (id UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID(), name VARCHAR(20))

INSERT INTO #test (name) VALUES ('boo')
INSERT INTO #test (name) VALUES ('woh')

SELECT *
FROM #test

UPDATE #test
SET name = 'whoops'
OUTPUT INSERTED.Id AS 'updated_id'
WHERE name = 'boo'

DELETE #test
Khanzor
i tried this but im getting Incorrect syntax near 'Updated'.
Geetha
Yeah, sorry, I revised my answer when I thought about what I was doing!
Khanzor
Thank You its working
Geetha