Friday, March 23, 2012

Order By clause problem

Hello,

Ive got a column which stores integers ranging from 0-200. I need to order them so that 1 is first, and 0 is last like 1,2,2,3,4,6,8...98...0,0,0

My Order By clause statement looks like 'ORDER BY column_name', but obviously this will put the '0' records at the top. Is there a way around this?

Thanks, Curt.

Do you have just one 0 record or more than 1?

|||

Use Case in your Order By clause:

OrderbyCASEWhen column_name=0then 201else column_nameEND

|||

i think you'll have to use union something like

select PID, Name from tt2 where PID%10 = 0
union
select PID, Name from tt2 where PID%10 <>0

thanks,

satish.

|||

Thanks limno, that works perfect.

sql

No comments:

Post a Comment