decimal日期取前一天
t1:
dt decimal(8,0)
原数据:
20070101
希望结果:(取前一天)
20061231
------解决方案--------------------declare @dt decimal(8,0)
set @dt = 20070101
select cast(stuff(stuff(cast(@dt as varchar(10)),5,0, '- '),8,0, '- ') as datetime)-1
------解决方案--------------------Declare @dt decimal(8,0)
Select @dt = 20070101
Select @dt = Convert(Varchar, DateAdd(dd, -1, Cast(@dt As Varchar)), 112)
Select @dt
--Result
/*
20061231
*/
------解决方案--------------------CREATE TABLE #T1(DT decimal(8,0))
INSERT #T1 SELECT '20070101 '
SELECT CONVERT(VARCHAR,DATEADD(DD,-1,RTRIM(DT)),112) FROM #T1
20061231