insert into inv120(partdate,part) select getdate(),part from inv100如上语句,是将inv100表中的数据添加到inv120中,我想验证,如果日期(yyyy-MM-dd,只看日期,小时分钟不计)和part在inv120表中已经存在,就不添加,若不存在,就添加。这个验证怎么加呀?

解决方案 »

  1.   

    insert into inv120(partdate,part) 
    select getdate(),part from inv100
    where not exists(select 1 
                     from inv120 
                     where convert(varchar(10),partdate120)=convert(varchar(10),t.partdate120))
      

  2.   

    --更正
    insert into inv120(partdate,part) 
    select getdate(),part from inv100 t
    where not exists(select 1 
                     from inv120 
                     where convert(varchar(10),partdate120)=convert(varchar(10),t.partdate120))
      

  3.   


    消息 207,级别 16,状态 1,第 5 行
    列名 'partdate120' 无效。
    消息 207,级别 16,状态 1,第 5 行
    列名 'partdate120' 无效。
      

  4.   

    insert into inv120(partdate,part) 
    select getdate(),part from inv100 t
    where not exists(select 1 
                     from inv120 
                     where convert(varchar(10),partdate,120)=convert(varchar(10),t.partdate,120))
      

  5.   


    消息 207,级别 16,状态 1,第 3 行
    列名 'partdate' 无效。
      

  6.   

    改了下insert into inv120(partdate,part) select getdate(),part from inv100 t
    where not exists(select 1 from inv120 i
    where convert(varchar(10),i.partdate,120)=convert(varchar(10),getdate(),120))
    好了,谢谢
      

  7.   

    掉,
    --更正
    insert into inv120(partdate,part) 
    select getdate(),part from inv100 t
    where not exists(select 1 
                     from inv120 
                     where convert(varchar(10),partdate,120)=convert(varchar(10),t.partdate,120))