工作当中日期排序的一个问题

有Table1 表
表结构:
MemberID int     ,Year  char(4),     Month varchar(2),     Day varchar(2),  Content varchar(60)
现在需要1900年3月的1 日到31 日进行排序:
因为Day是varchar类型
如果
select * from Table1 where Year='1900' and Month='3'  order by Day
排序是不是想要的,Day字段显示:
1
11
2
21
......
还是无序显示
为了解决这个问题,使用如下SQL语句:
select * from table1 where Year=1900 and Month=2 order by CONVERT(int,Day)
select CONVERT(int,Day) AS iDay FROM table1 where Year=1900 and Month=2 order by iDay
问题解决



select A5105 from LGBPInfo
假设 A5105是DateTime字段类型 显示:1905-03-13 00:00:00.000
修改
select convert(varchar(10),A5105,111)  from LGBPInfo 显示:1905/03/13  帮助里面说是 日本格式
select convert(varchar(10),A5105,101)  from LGBPInfo 显示    03/13/1905  美国格式
就是没有找到中国格式,只能凑合着用了
 
2006-1-20
Log 1:
工作中的一条Sql
select CheckManage_Guid,ExameID,case Convert(nvarchar,ExameDate,111) when '1900/01/01' then '' else Convert(nvarchar,ExameDate,111) end as ExameDate,Exameplace,ID,Examename,ExameContect,ExameResult,DealResult
from szcm_SR_CheckManage
where IsDel=0 order by Examename
这里
case Convert(nvarchar,ExameDate,111) when '1900/01/01' then '' else Convert(nvarchar,ExameDate,111) end as ExameDate
是实现日期的转换
szcm_SR_CheckManage  的表结构是:

原文地址:https://www.cnblogs.com/jhtchina/p/108143.html