2017-11-23 9 views
0

私は重複しないレコードを更新しようとしますが、構文が経過していない、それは重複したレコードを更新しないでください。

update #tempresult set prod_add=product.prod_made from product 
where (dep_no,prod_no,batch_no) not in 
(select dep_no ,prod_no ,batch_no from #tempresult 
group by dep_no ,prod_no ,batch_no having count(*)>1) 

tempresultの一時テーブルの構文は動作しませんが

create table #tempresult 
(
    dep_no char(16) not null, 
prod_no char(8) not null, 
batch_no char(12) not null, 
prod_add char(50) not null, 
dep_date datetime null, 
dep_num numeric(9,3) null, 
inv_num numeric(9,3) null, 
lest_num numeric(9,3) null, 
    buy_price numeric(12,6) null , 
row_index numeric(16, 0) IDENTITY(1,1) not null , 
primary key(dep_no,prod_no,batch_no,prod_add) 
) 

はあなたに感謝した

答えて

0

(エレガントな解決策ではないが)次のことを試してください。

update t set prod_add = 
        (
         select prod_made 
         from product p 
         where p.dep_no+'-'+p.prod_no+'-'+p.batch_no not in 
         (select dep_no+'-'+prod_no+'-'+batch_no from #tempresult 
         group by dep_no ,prod_no ,batch_no having count(*)>1) 
        ) 
from #tempresult t 
where dep_no+'-'+prod_no+'-'+batch_no not in 
    (select dep_no+'-'+prod_no+'-'+batch_no from #tempresult 
    group by dep_no ,prod_no ,batch_no having count(*)>1) 

ありがとうございます。

関連する問題