【问题标题】:insert data into another table using a multi select query使用多选查询将数据插入另一个表
【发布时间】:2015-10-20 10:20:56
【问题描述】:

我使用的是 sql server 2012。

我在下面写了一个选择查询,它工作正常。但是我不确定如何将查询返回的数据插入另一个表 (tblTempPrices)?

我的插入

;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

【问题讨论】:

    标签: sql sql-server sql-server-2012


    【解决方案1】:

    试试这样 -

    ;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;
    

    【讨论】:

      猜你喜欢
      • 2011-09-15
      • 2022-01-26
      • 2014-04-18
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      相关资源
      最近更新 更多