DECLARE @sql nvarchar(4000) DECLARE @cou int SET @sql='INSERT INTO people values('''+'xiaohong'+''');select @temp=@@IDENTITY' EXEC sp_executesql @sql, N'@temp int out', @cou OUT INSERT INTO child VALUES(@cou, '小兰')
CREATE PROC chjj @name nvarchar(1000) AS BEGIN DECLARE @sql nvarchar(4000) DECLARE @cou int SET @sql='INSERT INTO people values('''+@name+''');select @temp=@@IDENTITY' EXEC sp_executesql @sql, N'@temp int out', @cou OUT IF @cou > 85
BEGIN
INSERT INTO child VALUES(@cou, '小兰') END
END 调用存储过程:EXEC dbo.chjj '李厚鑫s'