sql - How to populate "between dates" given start and end dates -
i have table tells me start , end "reserve date" piece of equipment. want create , populate new table, filling in "between dates" along start , end date particular item. new table should include following columns:
item name conferencename reserved dates
i may 1 finds question quite interesting (- not explained).
here sql fiddle demo shows 1 way of doing using cursor populate dates. part of script believe asking shown below:
create table equipmentlog ([item name] varchar(255), conferencename varchar(255), [reserved dates] datetime); declare @item_name varchar(255), @conferencename varchar(255), @start_reserve_date datetime, @end_reserve_date datetime, @reserve_date datetime declare cur cursor fast_forward select * equipmentregister open cur fetch next cur @item_name, @conferencename, @start_reserve_date, @end_reserve_date while (@@fetch_status=0) begin set @reserve_date = @start_reserve_date while (@reserve_date <= @end_reserve_date) begin insert equipmentlog select @item_name, @conferencename, @reserve_date select @reserve_date = dateadd(day, 1, @reserve_date) end fetch next cur @item_name, @conferencename, @start_reserve_date, @end_reserve_date end close cur deallocate cur
Comments
Post a Comment