|
Home > Archive > MS SQL Server > March 2006 > order data
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi all,
someone could help me?
I need to order some records by data; the problem is the definition of
that data field: it' is't a datetime format, but nvarchar.
Thanks a lot
wa
| |
| Tibor Karaszi 2006-03-06, 7:23 am |
| The obvious question is why it isn't datetime...
That aside, you can convert the data in your ORDER BY clause to datetime (or a character
representation which sorts correctly), but we need to see what format you have for your date values
first.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www. solidqualitylearning
.com/
Blog: http:// solidqualitylearning
.com/blogs/tibor/
"Wasco" <wasco77@virgilio.it> wrote in message
news:1141633726.439178.133970@i40g2000cwc.googlegroups.com...
> Hi all,
> someone could help me?
> I need to order some records by data; the problem is the definition of
> that data field: it' is't a datetime format, but nvarchar.
>
> Thanks a lot
> wa
>
| |
|
| the format I have is nvarchar:
24/02/06 18.09.14
Could you post me an example pls?
Thank you in advance
wa
| |
| Uri Dimant 2006-03-06, 7:23 am |
| Hi
CREATE TABLE #Test
(
dt VARCHAR(20)
)
INSERT INTO #Test VALUES ('24/02/06 18.09.14')
INSERT INTO #Test VALUES ('22/02/06 17.15.14')
INSERT INTO #Test VALUES ('21/02/06 22.10.14')
INSERT INTO #Test VALUES ('28/02/06 04.09.14')
INSERT INTO #Test VALUES ('05/02/06 04.09.14')
SELECT * FROM #Test ORDER BY dt
---See the output
SELECT CAST('20'+SUBSTRING(
dt,5,2)+
SUBSTRING(dt,3,2)+SU
BSTRING(dt,1,2)+' '+SUBSTRING(dt,8,8)A
S DATETIME) AS
newdt FROM
(
SELECT REPLACE(REPLACE(dt,'
.',':'),'/','') AS dt FROM #Test
) as Der ORDER BY newdt
"Wasco" <wasco77@virgilio.it> wrote in message
news:1141634987.423331.180520@e56g2000cwe.googlegroups.com...
> the format I have is nvarchar:
> 24/02/06 18.09.14
> Could you post me an example pls?
> Thank you in advance
> wa
>
| |
|
| Thanks a lots!
I'm new on sql language.
|
|
|
|
|