Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with Sorting the column data on table

Author  Topic 

john20
Starting Member

30 Posts

Posted - 2008-04-09 : 07:56:50
Hi All,

I want to sort the column data which is of positive and negative number like the following.

-5823
-1
200
100

i want to sort like
-1
100
200
-5823

How can i do that can any one help me..

Thanks in advance.

-john

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-04-09 : 08:03:42
select * from table order by abs(x)

Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

john20
Starting Member

30 Posts

Posted - 2008-04-09 : 08:07:11
Hi Thanks for ur reply...

Tried the above solution but this only giving same result means

-5823
-1
200
100
i want

-1
100
200
-5823

Regards,
-john
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-09 : 08:13:42
Works for everyone else...
DECLARE	@Sample TABLE (i INT)

INSERT @Sample
SELECT -5823 UNION ALL
SELECT -1 UNION ALL
SELECT 200 UNION ALL
SELECT 100

SELECT *
FROM @Sample
ORDER BY ABS(i)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

pravin14u
Posting Yak Master

246 Posts

Posted - 2008-04-09 : 08:14:54
quote:
Originally posted by john20

Hi Thanks for ur reply...

Tried the above solution but this only giving same result means

-5823
-1
200
100
i want

-1
100
200
-5823

Regards,
-john



Give your query

Prakash.P
The secret to creativity is knowing how to hide your sources!
Go to Top of Page

john20
Starting Member

30 Posts

Posted - 2008-04-09 : 09:14:31

My Qyery is :

Select id from users order by id
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-09 : 09:15:18
quote:
Originally posted by john20

My Qyery is :
Select id from users order by id

Why don't you run the query given to you by Ryan and me?

Select id from users order by ABS(id)


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

john20
Starting Member

30 Posts

Posted - 2008-04-09 : 09:23:32
Hi All ,

Thanks its working now.....

Cheers
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-09 : 09:26:33
quote:
Originally posted by john20

Hi All ,

Thanks its working now.....

Cheers


Please read the replies carefully

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-09 : 09:27:47
quote:
Originally posted by RyanRandall

select * from table order by abs(x)

Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.


RyanRandall, nice to see you here after a long time

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-04-09 : 09:52:20
quote:
RyanRandall, nice to see you here after a long time

Madhivanan

Failing to plan is Planning to fail

Hi Madhi

Just passing through...

I see you and Peso are still prolific!


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -