How to get the last updated records primary key value (varchar)
I am using output inserted.PKfielName to get the varchar type primary key value of last inserted record.开发者_C百科 Now i want to get the primary key value of last updated record.
Geetha
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
精彩评论