views:

23

answers:

1

Hi All,

I want to select a value based on different column in SQL Server,

say

Result = Isnull(A.OUT1,'')<>'' then select A.OUT1
         Isnull(A.OUT2,'')<>'' then select A.OUT2
         Isnull(A.OUT3,'')<>'' then select A.OUT3

How to form query to get the Result?

+2  A: 

Do you mean something like this:

SELECT CASE 
         WHEN isnull(a.out1,'')  '' THEN a.out1
         WHEN isnull(a.out2,'')  '' THEN a.out2
         WHEN isnull(a.out3,'')  '' THEN a.out3
         ELSE ''
       END AS out_column
FROM the_table a
a_horse_with_no_name
Yes you are right
Gopi