SSRS Report with Business days as Expression - sql-server-2008

I have an SSRS report with the following header,
Date 28-Mar 27-Mar 25-Mar 24-Mar 23-Mar 22-Mar 21-Mar 20-Mar
Day Fri Thu Wed Tue Mon Sun Sat Fri
Pending 1 2 3 4 5 5 5 6
I able to generate Date and Day rows using expression with current date.
(e.g. = Left(WeekDayName(WeekDay(DateAdd("d",-1,Now()))),3))
But Pending Days row should display age in days with same age number for Mon, Sun and Sat since Sun and Sat are off days.
Is it possible to generate with expression?

Got it Guys,
We just need to make sum of no of 'mon', 'tus'..'fir' in the date range.
=DATEDIFF("ww",DateAdd("d",-1,Now()),Now(), vbMonday)
+
DATEDIFF("ww",DateAdd("d",-1,Now()),Now(), vbTuesday)
etc.
:)

Related

MySQL select multiple date range

I have a table with 2 dates: startDate and EndDate
I pass to my query 2 dates and I want to check if in this date range the offer are available.
I have an offer that is valid From 1 may 2019 to 30 may 2019.
When I search in offers, I want to show this only if the date range that I pass is included in the date range of the offer.
OFFER From 1 may 2019 to 30 may 2019
Value pass: 01 jan 2019 to 4 jan 2019 NO SHOW
Value pass: 28 april 2019 to 2 may 2019 NO SHOW
Value pass: 10 may 2019 to 12 may 2019 ONLY SHOW IN THIS CASE
Value pass: 29 may 2019 to 2 june 2019 NO SHOW
Value pass: 10 nov 2019 to 12 now 2019 NO SHOW
How can I do this?
This will work for MySQL.
date_from < '2019-10-05' AND date_to > '2019-10-12'

Find date scope from MySQL efficiently

Here is my DiscountPeriod table's structure:
id
room_id
date_from
date_last
discount
Imagine that we have discount starting 01 December 2017 and ending in in 10 December 2017.
I'm searching for date-range to see if it has discount.
So date range might be totally or partly inside some of discount periods. 3 example date-ranges for search:
From 02 December to 10 December (fully inside one of discount periods)
From 20 November to 4 December (partly inside)
From 5 December to 15 December (partly inside)
Expected for all of 3 examples above is to get discount that starts in 01 December 2017 and ends in 10 December 2017.
Currently my query takes only those results which is completely inside exact period from database.
It looks like this:
SELECT * FROM `DiscountPeriod` WHERE (`room_id`=1517) AND (`date_last` >= '2017-12-12') AND (`date_from` <= '2017-12-20');
Question is, how to fit all of 3 possible search cases into 1 query for efficient searching in MySQL database tables?
Expected result is
All of following scopes: From 02 Dec to 10 Dec, From 20 Nov to 4 Dec, From 5 Dec to 15 Dec should return back 1-10 december discount.
This looks like an overlapping range problem. If you want to return all discounts which overlap with 1-10 December 2017, then try the following query:
SELECT *
FROM DiscountPeriod
WHERE
room_id = 1517 AND
'2017-12-01' <= date_last AND '2017-12-10' >= date_from;
Here is a demo which uses your test data. All three discount ranges you suggested show up in the result set. But a range lying completely outside 1-10 December 2017 is absent, as we would expect.
Demo

MySQL Custom WEEK() Mode

I am trying to create a weekly report (including grouping by WEEK(date)) where weeks start on Monday. However, Week 1 is always the first week any day of a new year occurs. For example if Jan 1st is a Friday, that is week one.
This doesn't seem to be consistent with MySQL mode options for WEEK():
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week
Based on the available options it only works if the week has 4 or more days (options 1 and 3) or the Monday is in the new year (options 5 and 7). Neither of these account for example week 1 of 2016:
Wk Mon Tue Wed Thu Fri Sat Sun
No.
1 28 29 30 31 1 2 3
Is there any way to order/number the week numbers in MySQL based on this custom week mode requirement?

Reporting Services Quarterly Schedule instead running Monthly

I have a report in SSRS 2012 scheduled to run quarterly on a specific day i.e. 15th Jan, 15th Apr, 15th Jul & 15th Oct.
My shared schedule config is: Ticked 'Month', selected Jan, Apr, Jul & Oct, set 'On calendar day(s)' to '15'.
The schedule is displayed correctly but in fact runs on the 15th of each month.
Knowing these schedules are actually implemented using SQL Server Agent I inspect the job and find that the job in question has 4 schedules against it.
15th day of every 12 month starting on the 1 jan 2013
15th day of every 12 month starting on the 1 apr 2013
15th day of every 12 month starting on the 1 jul 2013
15th day of every 12 month starting on the 1 oct 2013
so that also makes sense.
Is there a fix to this issue?
I think the problem (and solution) is the same as described here https://techcommunity.microsoft.com/t5/System-Center-Blog/Support-Tip-Scheduled-backup-to-tape-runs-on-a-wrong-date-on-DPM/ba-p/347075

MySql Query- Date Range within a Date Range

I use mySql 5 and IIS.
I have products, that have a start date field and an end date field.
I need to run a query that will take user entered Start and End dates, and output the number of days that the product ran within the date range.
Example:
Offer1 - July 1 2011 thru July 31 2011
Query - July 1 2011 thru Sept 15 2011
Results = 31
Example:
Offer1 - July 1 2011 thru July 31 2011
Query - July 1 2011 thru July 15 2011
Results = 15
If your products have a start_date and an end_date and your query has a qstart_date and a qend_date, then we want the number of days between:
GREATEST(start_date, qstart_date)
and
LEAST(end_date,qend_date)
. In MySQL I think this looks like
1 + DATEDIFF ( 'd' , GREATEST(start_date, qstart_date) , LEAST(end_date,qend_date) )
And you'll want to ignore negative numbers, replacing them with "0".