Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling records through SQL quries

Status
Not open for further replies.

Palpa

Programmer
Jul 11, 2011
17
US
Hi there,

I am trying to creat a CASE WHEN Statement where it will pull the field which is not null from the list of given fields. Let say we have 10 fields with name Tag1, tag2, tag3 ..... tag10. Now what we need here is if the tag10 field is null then go to tag9 and if tag 9 is also null then go to tag8 and if tag8 is also null then go to tag7 and so on untill tag1. I tried but it is not working as it won't pass through first when statement. Any help regarding this will be greatly appreciated.

Thanks
 
was able to fix it myself with following query.

CASE WHEN PSMultiStratTags.Tag10 is not null THEN PSMultiStratTags.Tag10
else (case when PSMultiStratTags.Tag9 IS not null then PSMultiStratTags.Tag9
else (case when PSMultiStratTags.Tag8 IS not null then PSMultiStratTags.Tag8
else (case when PSMultiStratTags.Tag7 IS not null then PSMultiStratTags.Tag7
else (case when PSMultiStratTags.Tag6 is not null then PSMultiStratTags.Tag6
else (case when PSMultiStratTags.Tag5 IS not null then PSMultiStratTags.Tag5
else (case when PSMultiStratTags.Tag4 IS not NULL then PSMultiStratTags.Tag4
else (case when PSMultiStratTags.Tag3 IS not null then PSMultiStratTags.Tag3
else (case when PSMultiStratTags.Tag2 is not null then PSMultiStratTags.Tag2
else (case when PSMultiStratTags.Tag1 is not null then PSMultiStratTags.Tag1
end)end)end)end)end)end)end)end)end)
END AS "Rate Band
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top