Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2014-06-04 : 05:46:13
|
i have a list of data..how can i do it this way?if tableB columnA exist then named it as newcolumnExistif tableB columnA not exist then named it as newcolumnNotExisti tried this but it only appear those data that exist for 'master'select * from tableA join tableB on tableA.ID=tableB.IDwhere tableB.columnA='Master' |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-06-04 : 08:48:45
|
Perhaps this?select *, CASE WHEN tableB.columnA = 'Master' THEN 'newcolumnExist' ELSE 'newcolumnNotExist' END AS newColumnStatusfrom tableA join tableB on tableA.ID=tableB.ID |
 |
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2014-06-04 : 22:24:58
|
but this query still will show those which exist 'master':ID NewColumn1 newcolumnExist1 newcolumnNotExist |
 |
|
MuralikrishnaVeera
Posting Yak Master
129 Posts |
Posted - 2014-06-05 : 01:22:00
|
May be this change will help youSELECT * ,CASE WHEN TableB.columnA IS NOT NULL THEN 'newcolumnExist' ELSE 'newcolumnNotExist' END AS newColumnStatusFROM TableA LEFT JOIN TableB on TableA.ID=TableB.ID ---------------Murali KrishnaYou live only once ..If you do it right once is enough....... |
 |
|
|
|
|