select * from 表名 order by convert((CONVERT (varchar,日期,120)),datetime)
--> 测试数据:[tab] --> 测试时间:2009-07-06 17:08:06 --> AD.: http://shop36766744.taobao.com/if object_id('[tab]') is not null drop table [tab] create table [tab]([t] varchar(10)) insert [tab] select '05/08/2008' union all select '30/06/2008' union all select '25/02/2008'select t from tab order by right(t,4)+substring(t,charindex('/',t)+1,2)+left(t,2) /* t ---------- 25/02/2008 30/06/2008 05/08/2008(所影响的行数为 3 行)*/ drop table tab
order by right(col,4), right(left(co,5),2), left(col,2)
-- ========================================= -- -----------t_mac 小编------------- ---希望有天成为大虾---- -- =========================================IF OBJECT_ID('tb') IS NOT NULL DROP TABLE tb GO CREATE TABLE tb( times char(10)) go insert into tb select '05/08/2008' union all select '30/06/2008' union all select '25/02/2008' go select * from tb order by CONVERT(datetime,times,103) /*------------ 25/02/2008 30/06/2008 05/08/2008 -------*/
declare @t table(col1 char(10)) insert into @tselect '05/08/2008' union all select '30/06/2008' union all select '25/02/2008' select col1 from @t order by cast(right(col1,4)+'-'+substring(col1,4,2)+'-'+left(col1,2) as datetime) --这样就可以了
-- ========================================= -- -----------t_mac 小编------------- ---希望有天成为大虾---- -- =========================================IF OBJECT_ID('tb') IS NOT NULL DROP TABLE tb GO CREATE TABLE tb( times char(10)) go insert into tb select '05/08/2008' union all select '30/06/2008' union all select '25/02/2008' go select * from tb order by CONVERT(datetime,times,103) /*------------ 25/02/2008 30/06/2008 05/08/2008 -------*/ 有些记录没有数据?
--空的排后面 order by isnull(cast(col as datetime),getdate())--空的排前面 order by isnull(cast(col as datetime),'')
from 表名
order by convert((CONVERT (varchar,日期,120)),datetime)
--> 测试数据:[tab]
--> 测试时间:2009-07-06 17:08:06
--> AD.: http://shop36766744.taobao.com/if object_id('[tab]') is not null drop table [tab]
create table [tab]([t] varchar(10))
insert [tab]
select '05/08/2008' union all
select '30/06/2008' union all
select '25/02/2008'select t from tab
order by right(t,4)+substring(t,charindex('/',t)+1,2)+left(t,2)
/*
t
----------
25/02/2008
30/06/2008
05/08/2008(所影响的行数为 3 行)*/
drop table tab
right(col,4),
right(left(co,5),2),
left(col,2)
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
CREATE TABLE tb( times char(10))
go
insert into tb
select '05/08/2008' union all
select '30/06/2008' union all
select '25/02/2008'
go
select *
from tb
order by CONVERT(datetime,times,103)
/*------------
25/02/2008
30/06/2008
05/08/2008
-------*/
declare @t table(col1 char(10))
insert into @tselect '05/08/2008' union all
select '30/06/2008' union all
select '25/02/2008'
select col1 from @t order by cast(right(col1,4)+'-'+substring(col1,4,2)+'-'+left(col1,2) as datetime)
--这样就可以了
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
CREATE TABLE tb( times char(10))
go
insert into tb
select '05/08/2008' union all
select '30/06/2008' union all
select '25/02/2008'
go
select *
from tb
order by CONVERT(datetime,times,103)
/*------------
25/02/2008
30/06/2008
05/08/2008
-------*/
有些记录没有数据?
order by isnull(cast(col as datetime),getdate())--空的排前面
order by isnull(cast(col as datetime),'')