My query:
select SeqNo, Name, Qty, Price
from vendor
where seqNo = 1;
outputs like below:
SeqNo Name Qty Price
1 ABC 10 11
1 -do- 11 12
1 ditto 13 14
The output above shows the vendor name as ABC in first row which is correct. Later on as users entered for the same vendor name "ABC" as either '-do-' / 'ditto'. Now in my final query output I want to replace -do- and ditto with ABC (as in above example) so my final output should look like:
SeqNo Name Qty Price
1 ABC 10 11
1 ABC 11 12
1 ABC 13 14
this is working in sql server for you sample data..not sure how your other rows are look like
select SeqNo,
case when Name in ('-do-','ditto') then
(select Name from test where Name not in('-do-','ditto')
and SeqNo = 1)
else Name
end as Name
from table
where SeqNo = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With