Link to home
Start Free TrialLog in
Avatar of algotube
algotubeFlag for Canada

asked on

I have a sort order question

The following table has a series of text fields that I need to return in descending order.

Seq      Data String
1      2011-01-12-00.00.00.000000
2      2011-01-12-XX.00.00.000000
3      2011-01-12-XX-00.00.999999
4      2011-01-12-00.00.00.999999

How do I find out the sequence that these will be returned in descending order in SQL Server 2005?
This info is needed for comparison sake between IBM mainframe world and Oracle world.
Avatar of knightEknight
knightEknight
Flag of United States of America image

I'm not sure what you are asking.  Can't you just use ORDER BY col DESC to find out?

select top 100 *
from myTable
ORDER BY DataString DESC
Avatar of algotube

ASKER


This is what I received when I ran the query in SQL Server

SEQ      Data String

1            2011-01-12-00.00.00.000000
 2           2011-01-12-XX.00.00.000000
 3           2011-01-12-XX-00.00.999999
 4          2011-01-12-00.00.00.999999

This is what my buddy received when he ran it in IBM mainframe world

 
SORTED DESCENDING:
SEQ   DATA STRING
4     2011-01-12-00.00.00.999999
1     2011-01-12-00.00.00.000000
3     2011-01-12-XX-00.00.999999
2     2011-01-12-XX.00.00.000000


Why the difference................?????




SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You will have to find a common collation in order to sort the same way.
So for example you could use something like this to change the sort order to match the mainframe:
ORDER BY YourColumn COLLATE SQL_EBCDIC037_CP1_CS_AS
8080_Diver:  

Do you still have the query you used......if you do can you please post.  

Thank you so much for your help
algotube,

I must confess, I didn't use a query but, rather, just my knowledge of how the results would come out.

However, the query has already been posted (see response #35507991):
SELECT SEQ
      ,LTRIM(DataString)
FROM myTable
ORDER BY LTRIM(DataString) DESC

Open in new window


 In looking at the output you say you got, though, it would appear that you omitted the ORDER BY LTRIM(DataString) DESC line.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Guys I can't thank you enough for all your replies, very very much appreciated