I am seeking some help to build an SQL to obtain certain results. Below are two tables.
Table 1
Col1 | Col2 | Col3 | Col4 ---------------------------------------- TESTPC01 | 14/08/2014 | ABCD | CXYZ TESTPC02 | 14/08/2014 | EFGH | IJKL
Table2
COl1 | Col2 | Col3 | Col4 ---------------------------------------- TESTPC01 | 14/08/2014 | ENT | DOC
RESULT
COl1 | Col2 | Col3 | Col4 | Col5 | Col6 ------------------------------------------------------- TESTPC01 | 14/08/2014 | ENT | DOC | ABCD | YES | TESTPC02 | 14/08/2014 | EFGH | NULL | NULL | NO |
Yes only when there is data for that particular Col3 value is populated in the Table 2 for that specific matching Table1.Col1 = Table2.Col1.
If above condition fails then NO
I could build the SQL using simple select statements but no able to achieve to create the col6 dynamically. Can any one please guide me how to achieve this?