存储过程、插入数据后直接过去主键id

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'
sql存储过程怎么接收datatable作为入参

 

posted @ 2019-03-11 18:45  雷雨天的雷胖子  阅读(617)  评论(0编辑  收藏  举报