Author |
Topic |
AAAV
Posting Yak Master
152 Posts |
Posted - 2014-10-15 : 12:56:38
|
I have two tables TableA- ColA1 , ColA2, ColA3TableB- ColB1,ColB2,ColB3I want to select the rows from TableB.colB3where TableB ColB1 is null or ColA1 , TableB colB2 is null or ColA2 for every Row in TableA.ColA3<>nullCan it be done?Thanks |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-10-15 : 13:28:29
|
It can be done, but from your description it is not clear what the logic should be. It would help if you post some sample data and expected results. For example, in the following scenario, what should be the output?CREATE TABLE #tableA( cola1 INT, cola2 INT, cola3 INT);CREATE TABLE #tableB( colb1 INT, colb2 INT, colb3 INT);INSERT INTO #tableA ( cola1, cola2, cola3 )VALUES (1,2,0);INSERT INTO #tableB ( colb1, colb2, colb3 )VALUES (1, 3, 6), (2,2,7), (1,2,8),(NULL,NULL,9),(NULL,2,10); If you post sample data in consumable format like this (i.e., something that one can copy to a SSMS window and run), that would make it easier for someone to respond. |
|
|
AAAV
Posting Yak Master
152 Posts |
Posted - 2014-10-15 : 13:44:07
|
Here you gocreate table TableA(ColA1 int null,ColA2 int null,ColA3 int null)create table TableB(ColB1 int null,ColB2 int null,ColB3 int null)insert into TableA values (1,1,4)insert into TableA values (2,1,null)insert into TableA values (2,2,6)Insert into TableB values (1,null,6)insert into TableB values (1,1,7)insert into TableB values (2, 1,9)insert into TableB values (3,1,8)insert into TableB values (2, 2,8)select * from TableA where ColA3 is not nullselect * from TableB ColB1 ColB2 ColB31 NULL 6 -yes1 1 7 -yes2 NULL NULL -yes3 1 8 -No2 2 8 -Yes2 1 9 -NoThe table is joined on ColA1=ColB1 but I need the rows from b where ColB2 is null or the corresponding ColA2 |
|
|
AAAV
Posting Yak Master
152 Posts |
Posted - 2014-10-16 : 13:31:17
|
Igot it... thanks |
|
|
|
|
|