Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

How to update a record by checking a value in another record in same table

$
0
0

I have a table:

ID      DATE            RANGE       STATUS--------------------------------------------12330-SEP-2019     000         C12330-SEP-2019     001NULL34525-SEP-2019     000         C34530-SEP-2019     001NULL56730-SEP-2019     000         C56730-SEP-2019     001NULL78927-SEP-2019     000         C78930-SEP-2019     001NULL

Records with the same ID (for ex., 123) considered as same record with different RANGE. I need to update the STATUS of 001 RANGE records to Y for which 000 RANGE record should have the date as 30-SEP-2019.

Ex. Update query should update the STATUS to 'Y' for the record with the ID - '123' and RANGE - '001', because for the ID - '123' with the RANGE - '000' record's DATE is '30-SEP-2019'. Also it should update the STATUS of 001 RANGE record with the ID - 567.

It should not update the STATUS of 001 RANGE for the IDs 789 & 345, because those 000 RANGE record's DATE is not equal to 30-SEP-2019.

How can I achieve this?


Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>