Hi

I have a table which I need to update to value of Y, but this update is based upon some results from other tables, and I am not sure how to do this.

Basically, I need to complete the following checks

1) I need to check from the table I need to update that the other table has exactly 19 matching rows
2) In those matching rows that one of the fields is not null
3) I have two other tables which I need to check that records exist in the latter table plus to ensure that the matching records in the latter do not contain the value of "Y" in one of the fields.

My approach to this is to use UNIONs, but I would like someone to advise me whether this approach is correct or whether there is a much better way of doing it:

SELECT '1'
FROM t_A_Outbound
Where NOT HEADER IN (Select HEADER
FROM t_B_Outbound)
UNION
SELECT '1'
FROM t_A_Outbound
Where HEADER IN (Select HEADER
FROM t_B_Outbound
WHERE NOT INCOMPLETE ='Y')
UNION
Select '1'
From t_C_Outbound
Where ValueString = ''
UNION
Select '1'
From t_C_Outbound
WHERE Exists(Select Count(key), HEADER
From t_C_Outbound IN (SELECT HEADER FROM table_that_needs_updating)
Group By HEADER
Having NOT Count(Cast(key as Int)) = 19)

I thought of using 1 as flag to say if this value comes back to update the field in the table I need to change.

Can anyone advise me?