lundi 24 août 2015

Update column of different table based on manupulated result of another table

I have a table1 like below having more than 400k records.Below I'm just showing example, how it look likes. I want to write some query to itterate throgh each records and find its corresponding date; if all dates are present for the account ID , then I have to update another table2 "Yes". And, if any one of the date is null (for any account ID) then I have to update table2 flag as "No".This is my source table1.

Table1

 Account ID | Date
----------- |------------
   1        | 12-03-2015
   1        | 11-03-2015
   1        | 11-04-2015
   1        | 01-03-2015
   2        | 06-03-2015
   2        | 11-03-2015
   2        | Null
   2        | 01-03-2015

This is how the table2 result will look like (after query execution)

Table2

Account ID | Flag
-----------|------
1          | Yes
2          | No

2ndly, if after few days, Date of Account ID is changed from Null to an actual date (say 07-07-2015), then Table2 "Account ID 2" value should change from "No" to "Yes". So after few days the Table2 should look like this

Account ID | Flag
-----------|------
1          | Yes
2          | Yes

Hope I have explained it correctly.I'm thinking to use cursor, however, I'm not sure how to use this and will cursor really solve this problem? Is there any other ways to achieve this? Checked on net, however, not able to get suitable solution, please help?

Aucun commentaire:

Enregistrer un commentaire