Solved

Removing saturday and sunday from ssrs 2008 calendar report

Posted on 2013-11-11
3
631 Views
1 Endorsement
Last Modified: 2013-11-21
I used the following tutorial to create a calendar based report in SSRS. It is working but not exactly to what my requirements are,

My DBMS for scheduling ensures no tasks are added to Saturday's and Sunday's but I am not sure how to reflect that via this report the way it is currently built

Because of the way the query is built, right now tasks that aren't actually scheduled on a Saturday or Sunday are displaying as if they are because I haven't found  a way to filter out those days. I am hoping someone can tell me how to accomplish this.

http://rduclos.wordpress.com/2010/02/13/ssrs-2008-generate-calendars-based-on-a-date-range/

Thanks for any help!
1
Comment
Question by:J C
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 37

Expert Comment

by:ValentinoV
ID: 39640975
Ideally you'd have a Date dimension that contains a column to indicate which day of the week the record represents.  In that case you could just use a WHERE clause to filter out the weekend days.

Another option is to use either the DATEPART or DATENAME function.  Note that the result of DATEPART is influenced by the DATEFIRST setting, as following example indicates:

select DATEPART(dw, getdate())
select DATENAME(dw, getdate())

set datefirst 3;

select DATEPART(dw, getdate())
select DATENAME(dw, getdate())

Open in new window

0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 39641618
Include below highlighted where clause to filter saturday and sunday. HTH.


SELECT
 DisplayOnCalendar = DENSE_RANK() OVER (ORDER BY d.Year, d.Month),
 d.Month,
 [Day] = DATEPART(DAY,d.[Date]),
 d.Year,
 [WeekDay] = DATEPART(WEEKDAY, d.[Date]),
 [Order] = DENSE_RANK() OVER (PARTITION BY d.Year, d.Month ORDER BY d.Date),
 d.Date,
 ebd.FullName
FROM
 Dates d
 LEFT JOIN EmployeeBirthDay ebd ON ebd.Month = DATEPART(MONTH,d.[Date]) AND ebd.Day = DATEPART(DAY,d.[Date])
WHERE ((DATEPART(dw, d.[Date]) + @@DATEFIRST) % 7) NOT IN (0, 1)
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 39646182
Code below (also) works regardless of any date or language settings:

WHERE
    DATEDIFF(DAY, 0, d.[Date]) % 7 NOT IN (5, 6)
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question