INSERT SELECT语句是可以把SELECT查询返回结果集插入目标数据表中。
演示,首先创建一个临时表,
IF OBJECT_ID ('#t') IS NOT NULL
DROP TABLE #t
CREATE TABLE #t
(
[MemberId] [int] NOT NULL,
[Name] [nvarchar](100) NOT NULL,
[Job] [bit] NULL
)
使用INSERT SELECT语法,
INSERT INTO #t SELECT [MemberId],[Name],[Job] FROM [dbo].[Member] WHERE [Job] = 1
--或者
INSERT INTO #t([MemberId],[Name],[Job]) SELECT [MemberId],[Name],[Job] FROM [dbo].[Member] WHERE [Job] = 1