SQLTeam.com | Weblogs | Forums

Separate numbers to two different columns based on criteria


#1

Hi,

i created tabe which is contain only one column. in that column there are positive and negative values. By using query i want to separate positive values and negative values in two different columns. i tried but could not find the solution. pls help

Regards
Ajaypal


#2

Could be something like:

select case then yourfield<0 then yourfield else null end as negative
      ,case then yourfield>=0 then yourfield else null end as positive
  from yourtable
;

#3

Thanks for reply. But the query is not working.

While running above query, then output error says " Incorrect syntax near
the key word 'then' .

I removed 'then' after 'case' word.
Then output giving error as " Incorrect syntax error near '<'."

Pls help me.

Regards
SP.Ajay Pal


#4

Please show your code


#5

My fault. Do this instead:

select case when yourfield<0 then yourfield else null end as negative
      ,case when yourfield>=0 then yourfield else null end as positive
  from yourtable
;