一个sql日期转换问题,不是很明白
select space(8) as fsrq into #test0 where 0 = 1
declare @fsrq char(8)
set @fsrq='20141111'
while convert(char(8), @fsrq, 112) <= '20141211'
begin
insert #test0 (fsrq) select convert(char(8), @fsrq, 112)
select @fsrq = dateadd(day, 1, @fsrq)
end
select * from #test0
这样一段代码,进入了死循环,把代码改为下面的这种,也是跳不出。
select space(8) as fsrq into #test0 where 0 = 1 declare @fsrq char(8) set @fsrq='20141111' while @fsrq <= '20141211' begin insert #test0 (fsrq) select @fsrq select @fsrq = dateadd(day, 1, @fsrq) select @fsrq = convert(char(8),@fsrq,112) end select * from #test0
事实上第一种只要把char(8)换成datetime类型就一点问题都没有。
我是错在哪里了,请指点一二啊