我試圖將這個查詢來的記錄插入臨時表。任何幫助或建議將有幫助Sql臨時表除外
insert into #AddRec
select *
from stg di
right join
ED bp
on
bp.ID = di.ID
except
select *
from stg di
inner join
ED bp
on
bp.ID = di.ID
我試圖將這個查詢來的記錄插入臨時表。任何幫助或建議將有幫助Sql臨時表除外
insert into #AddRec
select *
from stg di
right join
ED bp
on
bp.ID = di.ID
except
select *
from stg di
inner join
ED bp
on
bp.ID = di.ID
如果您的選擇返回匹配插入表的字段數這應該工作!
insert into tbl1 (field1,field2)
select field1,field2 from.................
;WITH Q AS
(
select *
from stg di
right join
ED bp
on
bp.ID = di.ID
except
select *
from stg di
inner join
ED bp
on
bp.ID = di.ID
)
INSERT INTO #AddRec(... list of fields ...)
SELECT (... list of fields ...) FROM Q
,如果你想從頭開始創建臨時表,只需更換插入:
SELECT (... list of fields ...)
INTO #AddRec
FROM Q
#AddRec是一個表名和#嗎? – zod 2013-04-26 23:40:29
你可以發佈多一點的信息 - 哪個數據庫服務器的SQL Server 2012? #AddRec和其他兩個表的模式是什麼 – 2013-04-26 23:44:24
http://stackoverflow.com/questions/10656088/how-to-insert-into-select-but-one-field-is-from-somewhere-else – zod 2013-04-26 23:45:40