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 |
|
cimon
Starting Member
4 Posts |
Posted - 2009-06-01 : 12:34:15
|
| I have some table like this IDTABLEID OTHERCOLUMNSSKIN Othercolumn value1LUNGS Othercolumn value2KIDNEYS Othercolumn value3EYES Othercolumn value4I want the result as....if ID is skin select it under column ExternalID and if ID is Lungs select it under column heading internal id .Like thisExternalID InternalIDSKIN LUNGSso for this I did this SELECT ExternalID = CASE WHEN ID ='SKIN' THEN ID END, InternalID = CASE WHEN ID ='LUNGS' THEN ID ENDFROM IDTAbleWHERE ID IN (SKIN','LUNGS')This gives meExternalID InternalIDSKIN NULLNULL LUNGSHow do I get result as ExternalID InternalIDSKIN LUNGSHow do I select only non null values |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-01 : 13:00:30
|
| [code]SELECT ExternalID = MAX(CASE WHEN ID ='SKIN' THEN ID ELSE NULL END),TBCompliantID = MAX(CASE WHEN ID ='LUNGS' THEN ID ELSE NULL END)FROM IDTAbleWHERE ID IN (SKIN','LUNGS')[/code] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-01 : 13:43:20
|
Please don't edit your first post!We cannot see what has changed and the replies maybe then look wrong! No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
cimon
Starting Member
4 Posts |
Posted - 2009-06-01 : 15:24:17
|
Thank youthis works quote: Originally posted by visakh16
SELECT ExternalID = MAX(CASE WHEN ID ='SKIN' THEN ID ELSE NULL END),TBCompliantID = MAX(CASE WHEN ID ='LUNGS' THEN ID ELSE NULL END)FROM IDTAbleWHERE ID IN (SKIN','LUNGS')
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-02 : 12:39:58
|
| welcome |
 |
|
|
|
|
|