我有下一个代码,它在表可用性中插入完美的我的行。
with View_Solidnet_Training as
(
select cast('2013-04-09' as datetime) DateValue
union all
select DateValue + 1
from View_Solidnet_Training
where DateValue + 1 <= cast('2013-04-11' as datetime)
)
insert into OBJ_Availability
select 34, DateValue, 'AM', 2, 'Test' from View_Solidnet_Training;
但现在,他在新表中插入行后,他就停了下来。但是在循环之后,他必须在视图中下一行的新值中再次更改Start和EndDate:View_Solidnet_Training。
那么是否有可能的解决方案,或者我应该创建一个新的循环来检查视图的ID是否为零?
答案 0 :(得分:0)
据我了解你的问题,我认为你应该从将日期列入清单开始,然后插入。
样品:
create table Dates
(
startdate datetime,
endDate datetime
)
insert dates
SELECT '2013-04-06','2013-04-08'
SELECT * from Dates
Declare @date int
Declare @tbl table
(
date_ datetime
)
SELECT @date = datediff(day,startDate-1,EndDate) from Dates
SELECT @date
while(@date != 0 )
Begin
insert into @tbl
SELECT dateadd(day,@date,StartDate-1) from dates
set @date = @date -1
END
/*
--TO-DO
--Update StartDate and EndDate values in table Dates
-- insert YourTable
-- select date_ from @tbl
*/
SELECT * from @tbl
order by date_