2015-10-20 40 views
0

我使用的是2012年將數據插入到另一個表使用多選擇查詢

我已經寫了下面的工作正常選擇查詢的SQL Server。不過,我不知道如何將從我的查詢返回的數據插入到另一個表(tblTempPrices)?下面

我INSERT INTO

;insert into tblTempPrices(DateEntry, DatePrice, ISIN, Price, PriceSource, SecurityType, TableCheck) 

查詢工作

with ret as 
(
    select distinct ISIN, Price 
    from tblFI_Benchmark_R 
    where DateEntry = '2015-10-19' 
), 
stat as 
(
    select distinct ISIN, Price 
    from tblFI_Benchmark_S 
    where DateEntry = '2015-10-19' 
), 
allSec as 
(
    select * from ret 
    union 
    select * from stat 
) 
select '2015-10-20', '2015-10-19', ISIN, Price, 'BARC', 'FixedIncome', 'PCF' from allSec 

回答

3

嘗試這樣的 -

;with ret as 
    (
     select distinct ISIN, Price 
     from tblFI_Benchmark_R 
     where DateEntry = '2015-10-19' 
    ), 
    stat as 
    (
     select distinct ISIN, Price 
     from tblFI_Benchmark_S 
     where DateEntry = '2015-10-19' 
    ), 
    allSec as 
    (
     select * from ret 
     union 
     select * from stat 
    ) 
    insert into tblTempPrices(DateEntry, DatePrice, ISIN, Price, PriceSource, SecurityType, TableCheck) 
    select '2015-10-20', '2015-10-19', ISIN, Price, 'BARC', 'FixedIncome', 'PCF' from allSec; 
相關問題