July 11th, 2012, 01:16 PM
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:
Where NOT HEADER IN (Select HEADER
Where HEADER IN (Select HEADER
WHERE NOT INCOMPLETE ='Y')
Where ValueString = ''
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?