将一行含有日期范围的数据按照单日日期拆分

create table #temp(ids int identity(1,1), 日期 nvarchar(10))
declare @beginDate datetime
declare @endDate datetime
set @beginDate = '2009-06-01'
set @endDate = '2009-06-10'
declare @i int
set @i = 0
while @i <=datediff(DD,@beginDate,@endDate)
begin
insert into #temp
select convert(nvarchar(10), dateadd(dd,@i,@beginDate),120)
set @i = @i +1
end
select * from #temp

例如原表:ID/name/begdate/enddate

              1/张三/2011-12-1/2011-12-3

新的表:

ID/name/date

1/张三/2011-12-1

1/张三/2011-12-2

1/张三/2011-12-3

你可能感兴趣的:(日期)