Still playing around with tables and queries but need some help with a SQL Server query.
I have a table that looks like this.
VMName | DiskType | Status | Result
---------+------------+-------------+---------
TestVM1 | OS | Completed |
TestVM1 | Data | Completed |
TestVM2 | OS | Failed |
TestVM2 | Data | Completed |
TestVM2 | Data | Completed |
In the results column, I'd like to have it say "Completed" if both the OS and data disks have a status of completed.
If however, the OS disk shows failed, then the results column should show failed for all the disks of that VM.
Like this.
VMName | DiskType | Status | Result
---------+------------+-------------+---------
TestVM1 | OS | Completed | Completed
TestVM1 | Data | Completed | Completed
TestVM2 | OS | Failed | Failed
TestVM2 | Data | Completed | Failed
TestVM2 | Data | Completed | Failed
I tried cobbling together a query, but not sure what I'm doing wrong as it doesn't do anything.
UPDATE working_table t1
SET Result = 'Failed'
WHERE disktype = 'OS' AND
status = 'Failed' AND
NOT EXISTS (SELECT 1 FROM working_table t2 WHERE t1.VMname = t2.VMname);