I want to update the table IVRecords set IVNO = value return by a subquery
While (Select Count(*) From [IVRecords] Where IVNO= '22644') > 0
Begin
update [IVRecords] set IVNO= (Select a.IVNO from [DVHead] a inner join [IVRecords] b on a.DELIVERYNO=b.DELIVERYNO)
End
But the subquery return multiple value : 254,325,25346,25346 I have over 58000 records
So how to update the table IVRecords with the value return by subquery Select a.IVNO from [DVHead] a inner join [IVRecords] b on a.DELIVERYNO=b.DELIVERYNO) one by one?
The IVNo of IVRecords has the duplicated value 22644 caused by making mistake updation. And the IVNO of DVHead is the right IVNO of IVRecords. So I want to copy them to the IVRecords that has the wrong IVNo. 02 tables have key DELIVERYNO. My expected result: Before:
IVRecord
DELIVERYNO IVNO
253 22664
253 22664
456 22664
789 22664
DVHead
DELIVERYNO IVNO
253 1234
456 5236
789 6478
Expected result
IVRecord
DELIVERYNO IVNO
253 1234
253 1234
456 5236
789 6478