Quantcast
Channel: SQL Server Analysis Services forum
Viewing all articles
Browse latest Browse all 14337

Help with SQL query

$
0
0

I am trying to calculate the following:

We have group bookings held in our system as blocks. Blocks are not considered reservations until they are picked up and a rooming list entered so what I can see from the query below is the total revenue held on the block per group by arrival and departure date.

The problem is that the revenue per group is the total revenue shown is that generated during the whole period the bedrooms are blocked for. This would be ok if each group arrived and left in the same month. However, there are groups that arrive in a month and leave on the following month.

I need to split the revenue for these groups by month. So, for example if a group arrives on 28/06 and leaves on 3/07, I need to know how much of that revenue is generated in June and how much in July.

The query below is correct but will give me total revenue based on EndDate (check out date), so it will all go to the month the group checks out.

Select Year(BeginDate) ArrivalYear,

DATEDIFF(DAY,BeginDate, EndDate)AS StayNights, 

DATENAME(month, BeginDate)ASMonth,

GroupRef,

GADescriptionAS Decsription,

GAStatusASStatus,

SourceSiteId,

BeginDateAS Arrival,

EndDateAS Departure,

CreatedTimestamp,

DefMarketSegmentCodeAS MARKSEG,

ProjectedRevenueAccomNettAS AccomREV,

ProjectedRevenueFBNettAS FBRev

From SyncGroupRoomBlockHeaders

WHERE 

CreatedTimestamp<'2019-03-21'

AND BeginDate BETWEEN'2019-03-21'AND'2019-12-31'

or

 CreatedTimestamp <'2018-03-21'

AND BeginDate BETWEEN'2018-03-21'AND'2018-12-31'

OrderByMonth(BeginDate)


Viewing all articles
Browse latest Browse all 14337

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>