sql 2000 查询 日期问题

[复制链接]
查看11 | 回复5 | 2010-12-13 10:09:10 | 显示全部楼层 |阅读模式
原表中分5列存放日期如
a01a02 a03 a04 a05
2010 6
7
8
9
表示 2010年6月7日8时9分
我想在一个查询中把这个日期放到一列中 显示成“2010-06-07 08:09”这样的格式,小于10的前面要补0,应该怎么写啊???
谢谢!!

回复

使用道具 举报

千问 | 2010-12-13 10:09:10 | 显示全部楼层
alter table test add test nvarchar(50) --展示你要的结果
--test是我新建的表名alter table test add id int identity(1,1)--中间过程要用到,可以删除declare @count int declare @id intdeclare @year nvarchar(4)declare @month nvarchar(2)declare @day nvarchar(2)declare @hour nvarchar(2)declare @min nvarchar(2)set @id=1select @count=count(*
回复

使用道具 举报

千问 | 2010-12-13 10:09:10 | 显示全部楼层
用个临时表 table 换成你原表的名字就可以了select a01 , a02 ,a03 ,a04 ,a05 into #t from tableupdate a02='0'+convert(char(1),a02) from#t where len(a02)<2 update a03='0'+convert(char(1),a03)
回复

使用道具 举报

千问 | 2010-12-13 10:09:10 | 显示全部楼层
这个问题应该是显示问题,你在Javabean中设置一个日期转换函数,对你所查出的数据进行日期转化,SimpleDateFormatd对象进行格式转换
回复

使用道具 举报

千问 | 2010-12-13 10:09:10 | 显示全部楼层
select *,cast(a01 as varchar)+'-'+right('00'+cast(a02 as varchar),2)+'-'+right('00'+cast(a03 as varchar),2)+' '+right('00'+cast(a04 as varchar),2)+':'+right('00'+cast(a05 as va
回复

使用道具 举报

千问 | 2010-12-13 10:09:10 | 显示全部楼层
如果字段是字符型,可以把rtrim去掉select convert(varchar(16),cast((rtrim(a01)+'-'+rtrim(a02)+'-'+rtrim(a03)+' '+rtrim(a04)+':'+rtrim(a05)) as datetime),120)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行