I have a quarterly subscription SSRS report and is scheduled to run as follows
• November – January - report to be sent February 1st
• February – April - report to be sent May 1st
• May – July - report to be sent August 1st
• August – October - report to be sent November 1st
The report is generated on every month instead of above schedule. Recreated the subscription but no luck.
Created stored procedure as below.
CREATE PROCEDURE GetQuarterlydateinfo
AS
SET NOCOUNT ON ;
SELECT DATEADD(month, DATEDIFF(month, 0,getdate()), 0) AS StartOfMonth,
CONVERT(char(10), getdate(), 101) AS CurrentDate,
CASE WHEN MONTH(GETDATE()) = 2 THEN 'Q1'
WHEN MONTH(GETDATE()) = 5 THEN 'Q2'
WHEN MONTH(GETDATE()) = 8 THEN 'Q3'
WHEN MONTH(GETDATE()) = 11 THEN 'Q4'
ELSE 0
END As CurrentQuarter
RETURN
GO
Is there any way that i can use the above stored procedure and use those days to schedule the report.
Related
I have a requirement where the data needs to be retreived starting from a particluar month but for a years period only. Example would be all data dated from 1st August 2019 till a year after, which would be 1st August 2020. The month value could vary, so in this example it is August but it could be May or September as well.
SELECT
*
FROM
Reports
WHERE
Fromdate BETWEEN '2019-08-01' AND DATE_ADD('2019-08-01', INTERVAL 365 DAY)
ORDER BY dateFrom ASC;
Here between will only pick up data for 2019 and 365 days after but 2019 is baked in. How should i put the selection criteria in the between clause so that it is dynamic? I am thinking along the lines of below where i would declare a variable for the month but i am not sure how to specify the 365 days from that month.
set #monthSelected = 8; -- August
SELECT
*
FROM
Reports
WHERE
month(Fromdate) = #monthSelected
and Fromdate BETWEEN '2019-08-01' AND DATE_ADD('2019-08-01', INTERVAL 365 DAY)
ORDER BY dateFrom ASC;
This is what i came up with,
set #curYear = 2019 ;-- concat("'",Year(now()));
set #monthSelected = '10';
set #dateF = concat(#curYear,'-',#monthSelected,'-01',"'") ;
SELECT
*
FROM
Reports
WHERE
Fromdate BETWEEN #dateF AND DATE_ADD(#dateF , INTERVAL 365 DAY);
A bit crude and a bit on the slow slide but it seems to be working. Am open to hear other suggestions.
I am dissecting a report that was written by a previous employee. Can someone help me understand these lines?
Essentially I have been asked to find out if the report is pulling 2017 or 2018 data and these two lines are the only parameters within them.
AND RecordDate >= CASE WHEN MONTH(GETDATE()) >=10 THEN DATEFROMPARTS(YEAR(GETDATE()), 10,1) ELSE DATEFROMPARTS(YEAR(GETDATE())-1,10,1) END
AND RecordDate < CASE WHEN MONTH(GETDATE()) >=10 THEN DATEFROMPARTS(YEAR(GETDATE())+1, 10,1) ELSE DATEFROMPARTS(YEAR(GETDATE()),10,1) END
This pair of conditions dynamically filter the dataset for the a dynamic period that ranges from the first of October to end of September, like a fiscal year.
CASE WHEN MONTH(GETDATE()) >=10
THEN DATEFROMPARTS(YEAR(GETDATE()), 10,1)
ELSE DATEFROMPARTS(YEAR(GETDATE())-1,10,1)
END
The first case expression computes the lower bound of the period: it gives you October 1st of last year if current date is before October 1st, else October 1st this year (i.e. a new fiscal year started).
The other expression uses similar logic to compute the upper bound.
I have build an SSRS report. I set a default date parameters as following:
startdate : take the first day of the month.
EndDate : take yesterday date.
This code for the beginning of the month
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(0)
This code for yesterdate date
=DateAdd(DateInterval.Day,-1,CDate(FormatDateTime(Now,DateFormat.ShortDate)))
The date works perfectly until, a new month comes, the result will be like this:
startdate: 01. 5 2019
end date: 30. 4 2019
where it should be :
startdate: 01. 4 2019
end date: 30. 4 2019
how can i make sure if a new date comes , it will take the first day of the previous month.
You should add an IIF statement to check if today is the first day of the month. The following expression should do what you need.
=IIF(DatePart(DateInterval.Day, Today()) = 1,
DateSerial(Year(Now()), Month(Now())-1, 1),
DateSerial(Year(Now()), Month(Now()), 1))
Just change your StartDate to reference yesterday's date:
=DateSerial(Year(Today.AddDays(-1)),Month(Today.AddDays(-1)),1)
I have created a ssrs report and this report display last 12 months data. I have 2 parameters startDate and Enddate.
The End date is always the current month and I want the start date to be the last 12 months. For example if my (End Date) current month is JAN 2018. I want my start date to be Feb 2017.
I have below expression but this give me Jan 2017 date for my start date.
=DateAdd("M", -12,Today())
Try this expression for the start date parameter default value.
=DateAdd(DateInterval.Year, -1, DateAdd(DateInterval.Month, 1, Parameters!EndDate.Value))
Here's what the parameter values would equal:
Having some problems getting the information I need from the database. I fell foul of the week vs iso_week setting in DATEPART but have now got the problem of getting the year from it. The nub of the issue is that when I run
SELECT datePart(iso_week, '2014-12-29');
SELECT datePart(week, '2014-12-29');
SELECT datePart(YEAR, '2014-12-29');
I get Wk 1 for the first query, Wk 53 for the second. (first being what I want) but the year is still 2014. So if I do
SELECT CONCAT('WK', RIGHT(CONCAT('00', DATEPART(iso_week, '2014-12-29')), 2), ' ', DATEPART(year, '2014-12-29'))
I get WK01 2014 instead of WK01 2015.
Anyone know a way I can get the right ISO week and the associated year for a date?
Edit:
See if I can clear up a bit here.
Not expecting the above to return 2015 instead of 2014, that would be daft. What I need is a way to know that the week number returned is actually in the next year. I did consider doing a straight if week > 52 then its wk 1 in the next year, but that seems a little sledgehammerish and I am not sure it will actually work.
You should understand how the ISO_WEEK is calculated. From Microsoft:
ISO 8601 includes the ISO week-date system, a numbering system for
weeks. Each week is associated with the year in which Thursday occurs.
For example, week 1 of 2004 (2004W01) ran from Monday 29 December 2003
to Sunday, 4 January 2004. The highest week number in a year might be
52 or 53. This style of numbering is typically used in European
countries/regions, but rare elsewhere.
Hence your DATEPART(YEAR, ...) you should pass in the Thursday on or after December 29, 2014.
Try this
SELECT CONCAT('WK', RIGHT(CONCAT('00', DATEPART(iso_week, '2014-12-29') % 53), 2), ' ', DATEPART(year, '2014-12-29') + DATEPART(iso_week, '2014-12-29') % 53)
Had someone set me on the right track with some simple logic. I was trying to over complicate things. This seems to work for everything I can throw at it.
DECLARE #date AS DATETIME
SET #date = '2014-12-29'
SELECT
CAST(
CASE
WHEN MONTH(#Date) = 1 AND DATEPART(iso_week, #date) > 51 THEN YEAR(#Date) - 1
WHEN MONTH(#Date) = 12 AND DATEPART(iso_week, #date) = 1 THEN YEAR(#Date) + 1
ELSE YEAR(#Date)
END
AS VARCHAR(4)) AS Year
,
RIGHT('00' + CAST(DATEPART(iso_week, #date) AS VARCHAR(2)), 2) AS Week
It seems to cover true wk53 occurrences and incorrect ones.