Groups | Blog | Home
all groups > sql server connect > august 2007 >

sql server connect : help in a query plzzz


Adi
8/23/2007 3:50:33 PM
hi, i have a simple question, mit look silly question for some one..
but please look into it n let me know how to write a query for it.. i
have 3 cols

col1 col2 col3
----- ----- ------
123 null 1159
434 null 1159
555 233 1490
999 null 1440
234 667 1159

the result set should consist of details where col3=1159 in a single
col..

col
-----
123
434
234-667

select (case RTRIM(col2)
when null then RTRIM(col1)
else RTRIM(col1) + '-' + RTRIM(col2)
end) col
from table where col3 =1159

but i get the result as follows

col
----
null
null
234-667

can you please help in getting the result.. thanks
Aditya
Adi
8/23/2007 4:15:53 PM
[quoted text, click to view]

problem solved..

select (case
when RTRIM(col2) is null then RTRIM(col1)
else RTRIM(col1) + '-' + RTRIM(col2)
end) col
from table where col3 =1159

this statement worked fine..
AddThis Social Bookmark Button