我在下面写一个查询,
WITH muhammed AS(
SELECT * FROM acct_db2016.dbo.acct_tran WHERE trc_acno='12008001'
UNION
SELECT * FROM acct_db.dbo.acct_tran WHERE trc_acno='12008001')
SELECT * FROM muhammed
我想插入如下给出的
INSERT INTO acct_db2016.dbo.acct_tran SELECT * FROM muhammed
怎么做?
答案 0 :(得分:0)
WITH muhammed AS(
SELECT * FROM acct_db2016.dbo.acct_tran WHERE trc_acno='12008001'
UNION
SELECT * FROM acct_db.dbo.acct_tran WHERE trc_acno='12008001'
)
INSERT INTO acct_db2016.dbo.acct_tran -- <-- put the insert at this line
SELECT * FROM muhammed -- <-- Why you are inserting duplicate data from the first table?