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.
Author |
Topic |
seeker62
Starting Member
40 Posts |
Posted - 2013-09-17 : 13:48:05
|
in sql 2010 I have a date field and when i do a sort asc the dates appear in similar order as 7/1,7/15,7/22,7/8. I am guessing that the sort is reading 7/8 as 7/80 instead of 7/08. How can i force the sort correctly. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-17 : 13:58:34
|
Why are the dates not stored using DATE data type?What is the reason for storing the dates using VARCHAR datatypes?SELECT * FROM dbo.Table1 ORDER BY 0 + SUBSTRING(Col1, CHARINDEX('/', Col1) + 1, LEN(Col1)), 0 + SUBSTRING(Col1, 1, CHARINDEX('/', Col1) - 1) Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
seeker62
Starting Member
40 Posts |
Posted - 2013-09-17 : 14:03:30
|
that is the confuseing part. They are DATE field. I left off the year just for simplification |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-17 : 14:38:51
|
Which sort order do you want then? Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
seeker62
Starting Member
40 Posts |
Posted - 2013-09-17 : 14:42:26
|
asc |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-17 : 14:53:09
|
Ascending according to what? year, month and day? It so, just do a ORDER BY Col1.Then they are SORTED. Then how they are represented and displayed, it's up to you and your current locale and regional settings. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
 |
|
|
|
|
|
|