实现和下面相同功能,但不能使用with,因为with是一个关键字
with f as (select   *  from     up_def   where   price_id='1' and e_dd>=getdate()) select * into #xs_price from f t where not exists(select 1 from f where prd_no=t.prd_no and sys_date>t.sys_date)

解决方案 »

  1.   

    select * into #f from up_def where price_id='1' and e_dd>=getdate()select * into #xs_price from #f t 
    where not exists(select 1 from #f where prd_no=t.prd_no and sys_date>t.sys_date)drop table #f
      

  2.   

    insert into #xs_price
    select * from up_def where price_id='1' and e_dd>=getdate()
    and  not exists(select 1 from f where prd_no=t.prd_no and sys_date>t.sys_date)
      

  3.   


    select * into #xs_price from f t 
    where not exists(select 1 from 
    (select * from up_def where price_id='1' and e_dd>=getdate()) t 
    where prd_no=t.prd_no and sys_date>t.sys_date)
      

  4.   

    select t.* into #xs_price from f t where price_id='1' and e_dd>=getdate() and not exists(select 1 from f where price_id='1' and e_dd>=getdate() and prd_no=t.prd_no and sys_date>t.sys_date)
      

  5.   

    ;with f as (select * from up_def where price_id='1' and e_dd>=getdate()) select * into #xs_price from f t where not exists(select 1 from f where prd_no=t.prd_no and sys_date>t.sys_date)其实你加个分号就能跑了
      

  6.   

    select * into #f from up_def where price_id='1' and e_dd>=getdate()
    select
     * 
    into
     #xs_price 
    from
     #f t 
    where
     not exists(select 1 from #f where prd_no=t.prd_no and sys_date>t.sys_date)
    drop table #f
      

  7.   

    抱歉,你们2#,3#可能理解错了,都提示f不存在,f和t都是结果集,不是真正的表名.估计只有1楼可以,能不能写一条语句呢
      

  8.   

    看下5楼,我估计你是对cte的理解有点问题
    你在你的语句前面加个分号,就不会报错了
    如果你硬是要不用cte而重新搞了一条语句实现的,当我没说