Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have the following SQL:

;WITH times AS (
    SELECT '0830' AS t
    UNION
    SELECT '0930' AS t
    UNION
    SELECT '1030' AS t
    UNION
    SELECT '1130' AS t
    UNION
    SELECT '1230' AS t
)
SELECT t as time
FROM times
;

When I execute this in SSMS (SQL Server Management Studio), it displayed correctly as

0830
0930
1030
1130
1230

However, when I put this into a drop down list inside Visual Studio 2010, the list becomes incorrectly sorted:

1030
1130
1230
830
930

The 0 is disappearing from the 0830 and 0930 and both 0830 to 0930 is being shifted from the 1st two items in the list to the last two items.

How can I make the drop-down show the list in the correct order?

share|improve this question

closed as off topic by Jon Seigel, RolandoMySQLDBA, Derek Downey, Leigh Riffel, Marian Oct 10 '12 at 12:36

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Your application is sorting it based on the character values (i.e. a string sort, as opposed to a numeric one). If SQL Server is handing the application the data correctly, then this sounds like an application issue. –  Thomas Stringer Sep 27 '12 at 3:09
1  
How about ORDER BY CONVERT(INT, time)? Or using a TIME data type instead of a string? –  Aaron Bertrand Sep 27 '12 at 3:26
1  
Despite the lack of an ORDER BY, this is an application issue, probably something to do with data types and how the list is getting populated. –  Jon Seigel Sep 27 '12 at 3:26
    
While the solution seems to have been simple enough, I wonder if the difference could be a plan issue based on different session settings (e.g. the same kind of issue that often causes an app to be slow but SSMS to be fast). –  Aaron Bertrand Sep 27 '12 at 12:19

1 Answer 1

up vote 1 down vote accepted

Specials thanks to Shark, Aaron Bertrand and Jon Seigel that have enlighten me.

I have use the ORDER BY CONVERT(INT, time) and it now solved the application issue problem. (Fortunately, the change to the SQL statement was a quick way to solve this problem)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.