日期:2014-05-19  浏览次数:20495 次

急!请教一个sql的日期转换问题~!高手请进!! 在线等!
取系统当前日期转换为数字类型
如   '2007-06-19   07:20:00 '   转为   70619072000  
我只能专成70619,后面转换不了,请高手指教!
谢谢~!

------解决方案--------------------
declare @a smalldatetime
set @a= '2007-06-19 07:20:00 '

select ltrim(cast(convert(varchar(10),@a,12) as int))+replace(convert(char(8),@a,108), ': ', ' ')
------解决方案--------------------
DECLARE @i smalldatetime
SET @i= '2007-06-19 07:20:00 '

SELECT RIGHT(REPLACE(REPLACE(REPLACE(CONVERT(nchar(19),@i,20), '- ', ' '), ': ', ' '), ' ', ' '),11)
------解决方案--------------------
select replace(replace(replace(convert(varchar(30),getdate(),120), '- ', ' '), ': ', ' '), ' ', ' ')

--结果
20070619170502
------解决方案--------------------
select right(replace(replace( replace(convert(varchar(30), '2007-06-19 07:20:00 ',120), '- ', ' '), ': ', ' '), ' ', ' '),11)


------解决方案--------------------
select date = (datepart(YY,date)+datepart(mm,date)+datepart(dd,date)+datepart(hh,date)+datepart(mi,date)+datepart(ss,date) )