我有一个存储过程 usp_GetValues。
EXEC usp_GetValues '123' gives a list of names like :
Names
=======
Joy
Roy
Toy
我有另一个表,我想在其中插入记录,例如:
插入 NewNameTable 值('HighSchool'、Names、'true')
其中名称列表将来自存储过程执行。
有没有办法做这个批量插入?
我有一个存储过程 usp_GetValues。
EXEC usp_GetValues '123' gives a list of names like :
Names
=======
Joy
Roy
Toy
我有另一个表,我想在其中插入记录,例如:
插入 NewNameTable 值('HighSchool'、Names、'true')
其中名称列表将来自存储过程执行。
有没有办法做这个批量插入?
试试这个 ...
CREATE TABLE #TestTable ([Names] NVARCHAR(256))
INSERT INTO #TestTable
EXEC usp_GetValues '123'
Insert into NewNameTable Select ('HighSchool', Names, 'true') from #TestTable
首先将执行存储过程的名称值存储在临时表中,然后使用默认值插入目标表。
DECLARE @tempNameTable table(names varchar(100))
INSERT INTO @tempNameTable
EXEC usp_GetValues '123'
INSERT INTO NewNameTable
SELECT 'High School',names,'true'
FROM @tempNameTable