Get last inserted UNIQUEIDENTIFIER in SQL Server 2000

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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 


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