Get last inserted UNIQUEIDENTIFIER in SQL Server 2000

不想你离开。 提交于 2019-12-19 17:35:20

问题


The OUTPUT clause is compatible with SQL Server 2005 but not SQL Server 2000.

How do I convert this command to work in SQL Server 2000?

CREATE TABLE sample
(
 ID uniqueidentifier NOT NULL DEFAULT newid(),
 Title varchar(30) NOT NULL
)

INSERT INTO sample (Title)
OUTPUT INSERTED.ID
VALUES ('Test1')

I need the command to retrieve the ID since the INSERT command needs to be called from a stored procedure.

Thanks for any help!


回答1:


DECLARE @uid uniqueidentifier 
SET @uid  = newid()

INSERT INTO sample (ID, Title)
VALUES (@uid,'Test1')

SELECT @uid AS ID


来源:https://stackoverflow.com/questions/5863168/get-last-inserted-uniqueidentifier-in-sql-server-2000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!