| Author |
Topic  |
|
|
AskSQLTeam
Ask SQLTeam Question
USA
0 Posts |
Posted - 11/17/2006 : 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
USA
12780 Posts |
|
|
robvolk
SQLTeam MVY/MIA
USA
12325 Posts |
Posted - 11/17/2006 : 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
Slovenia
11645 Posts |
Posted - 11/17/2006 : 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 all
select convert(varchar(200), getdate()+1, 107) union all
select convert(varchar(200), getdate()+3, 107) union all
select convert(varchar(200), getdate()+2, 107) union all
select convert(varchar(200), getdate(), 107)
SELECT * FROM @t1
select distinct t1.*
from @t1 t1
cross join @t1 t2
where 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
USA
4184 Posts |
Posted - 11/17/2006 : 13:37:16
|
NERD
LOSER
NERD

How you doing?
MeanOldDBA derrickleggett@hotmail.com
When life gives you a lemon, fire the DBA. |
 |
|
|
spirit1
Cybernetic Yak Master
Slovenia
11645 Posts |
Posted - 11/17/2006 : 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
USA
4184 Posts |
Posted - 11/17/2006 : 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.
MeanOldDBA derrickleggett@hotmail.com
When life gives you a lemon, fire the DBA. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
USA
6298 Posts |
Posted - 11/17/2006 : 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
Slovenia
11645 Posts |
|
|
robvolk
SQLTeam MVY/MIA
USA
12325 Posts |
Posted - 11/17/2006 : 21:20:44
|
No, I'm gonna ruin it:
SELECT varcharDateColumn FROM myTable ORDER BY cast(varcharDateColumn as datetime) |
 |
|
|
madhivanan
Premature Yak Congratulator
India
20644 Posts |
Posted - 11/18/2006 : 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 dates
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
USA
12780 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
USA
6298 Posts |
Posted - 11/20/2006 : 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
USA
12780 Posts |
Posted - 11/20/2006 : 15:10:29
|
quote: Originally posted by Michael Valentine Jones
Obviously, the application will ensure that there are no bad dates in the varchar date column.
[smacks forehead] What was I thinking [/smacks forehead]
Brett
8-)
Hint: Want your questions answered fast? Follow the direction in this link http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Add yourself! http://www.frappr.com/sqlteam
|
Edited by - X002548 on 11/20/2006 15:10:49 |
 |
|
| |
Topic  |
|