| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-11-17 : 10:24:28
|
| saras writes "In sql server ,How to Sort a date which is converted into varchar.I need a single column" |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-11-17 : 10:29:37
|
While I did kill a few quality brain cells last night, I just can't muster the ability to come up with these questions myself. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-17 : 13:35:29
|
unfortunatly there's no way simple way to order dates converted to varchar.you could try this workaround:declare @t1 table (col1 varchar(200))insert into @t1 select convert(varchar(200), getdate()+4, 107) union allselect convert(varchar(200), getdate()+1, 107) union allselect convert(varchar(200), getdate()+3, 107) union allselect convert(varchar(200), getdate()+2, 107) union allselect convert(varchar(200), getdate(), 107) SELECT * FROM @t1select distinct t1.*from @t1 t1 cross join @t1 t2where t1.col1 <= t2.col1 Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-11-17 : 13:37:16
|
NERDLOSERNERD How you doing?MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-17 : 13:39:48
|
derrick where have you been lately... we missed you Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-11-17 : 14:00:23
|
I've took a position at AMC Theatres running the information services department. Now, I'm buried. I happen to be at PASS this week, so I have more time to post. Hopefully, my time will begin to free up as we get structure, processes, etc in place and start to work a plan. You know how new jobs go.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-11-17 : 14:05:09
|
quote: Originally posted by AskSQLTeam saras writes "In sql server ,How to Sort a date which is converted into varchar.I need a single column"
Use an ORDER BY clause.CODO ERGO SUM |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-17 : 14:11:16
|
you ruin all the fun Michael Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-11-17 : 21:20:44
|
| No, I'm gonna ruin it:SELECT varcharDateColumn FROM myTable ORDER BY cast(varcharDateColumn as datetime) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-18 : 04:35:19
|
quote: Originally posted by AskSQLTeam saras writes "In sql server ,How to Sort a date which is converted into varchar.I need a single column"
You should always use proper datatype DATETIME to store datesMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-11-20 : 15:07:44
|
| Obviously, the application will ensure that there are no bad dates in the varchar date column.CODO ERGO SUM |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|