SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sorting Date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 11/17/2006 :  10:24:28  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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

Posted - 11/17/2006 :  10:27:31  Show Profile  Visit X002548's Homepage  Reply with Quote
Rob is now just messing with us



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



Go to Top of Page

robvolk
SQLTeam MVY/MIA

USA
12325 Posts

Posted - 11/17/2006 :  10:29:37  Show Profile  Visit robvolk's Homepage  Reply with Quote
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.
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11645 Posts

Posted - 11/17/2006 :  13:35:29  Show Profile  Visit spirit1's Homepage  Reply with Quote
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
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

USA
4184 Posts

Posted - 11/17/2006 :  13:37:16  Show Profile  Visit derrickleggett's Homepage  Send derrickleggett an AOL message  Send derrickleggett a Yahoo! Message  Reply with Quote
NERD

LOSER

NERD



How you doing?

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11645 Posts

Posted - 11/17/2006 :  13:39:48  Show Profile  Visit spirit1's Homepage  Reply with Quote
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
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

USA
4184 Posts

Posted - 11/17/2006 :  14:00:23  Show Profile  Visit derrickleggett's Homepage  Send derrickleggett an AOL message  Send derrickleggett a Yahoo! Message  Reply with Quote
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.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
6298 Posts

Posted - 11/17/2006 :  14:05:09  Show Profile  Reply with Quote
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
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11645 Posts

Posted - 11/17/2006 :  14:11:16  Show Profile  Visit spirit1's Homepage  Reply with Quote
you ruin all the fun Michael



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

robvolk
SQLTeam MVY/MIA

USA
12325 Posts

Posted - 11/17/2006 :  21:20:44  Show Profile  Visit robvolk's Homepage  Reply with Quote
No, I'm gonna ruin it:

SELECT varcharDateColumn FROM myTable ORDER BY cast(varcharDateColumn as datetime)
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
20644 Posts

Posted - 11/18/2006 :  04:35:19  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
Go to Top of Page

X002548
Not Just a Number

USA
12780 Posts

Posted - 11/20/2006 :  15:02:25  Show Profile  Visit X002548's Homepage  Reply with Quote
quote:
Originally posted by robvolk

No, I'm gonna ruin it:

SELECT varcharDateColumn FROM myTable ORDER BY cast(varcharDateColumn as datetime)



That could blow up if one of the values is not valid, no?



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



Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
6298 Posts

Posted - 11/20/2006 :  15:07:44  Show Profile  Reply with Quote
Obviously, the application will ensure that there are no bad dates in the varchar date column.







CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

USA
12780 Posts

Posted - 11/20/2006 :  15:10:29  Show Profile  Visit X002548's Homepage  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000 Version 3.4.03