[英]insert temp table with multiple select statement
我的程序中有一個臨時表; 我試圖從這樣的select語句插入數據:
INSERT INTO #temptable
SELECT fee, expense, total FROM invoice
UNION
SELECT vat, holdingtax, total FROM uplifts
...但是在我的temptable中 ,只有第一個select語句填充到表中,而下一個select語句不插入數據。
語法看起來不錯,
第二個表中可能有重復項。
您可以使用Union All而不是Union進行測試。
我只運行查詢而不插入,以查看是否返回期望的結果。
我假設UNION正在刪除重復的數據。 我剛剛對Union ALL進行了測試:
insert into #temptable
select top 1 name from sys.tables
union all
select top 1 name from sys.tables a
我受了(2 row(s) affected)
嘗試用UNION ALL替換UNION
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.