Hi
I am brand new user - only my second post! Using 2008R2 - I have a report using an events table which contains datefrom and dateend dates. The from and end can be over a number of days but I need to group and display the event every day it runs. For example if event runs June 1st thru' June 3rd I need to display it on June 1, June 2, June 3. I thought the only way to do it would be to create a temporary table so have been provided with the following code. Problem is I'm not a developer and I don't know what to do with it! Can anyone give me a step by step guide? Thanks.
CREATE PROCEDURE BOOKINGS @START_DATE datetime, @END_DATE datetime, @bookingid int
AS
BEGIN
-- create temp table to store each row
CREATE TABLE #bookings
(
ID INT,
MYDATE datetime
)
-- iterate through each day in the range and insert a row per day along with the booking id
WHILE(@FROM_DATE < @END_DATE)
BEGIN
insert into #bookings
values(@bookingid,@FROM_DATE)
set @FROM_DATE = DATEADD(day, 1, @FROM_DATE)
END
I am brand new user - only my second post! Using 2008R2 - I have a report using an events table which contains datefrom and dateend dates. The from and end can be over a number of days but I need to group and display the event every day it runs. For example if event runs June 1st thru' June 3rd I need to display it on June 1, June 2, June 3. I thought the only way to do it would be to create a temporary table so have been provided with the following code. Problem is I'm not a developer and I don't know what to do with it! Can anyone give me a step by step guide? Thanks.
CREATE PROCEDURE BOOKINGS @START_DATE datetime, @END_DATE datetime, @bookingid int
AS
BEGIN
-- create temp table to store each row
CREATE TABLE #bookings
(
ID INT,
MYDATE datetime
)
-- iterate through each day in the range and insert a row per day along with the booking id
WHILE(@FROM_DATE < @END_DATE)
BEGIN
insert into #bookings
values(@bookingid,@FROM_DATE)
set @FROM_DATE = DATEADD(day, 1, @FROM_DATE)
END