Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Script to Return Last Weeks Data

By SALIM ALI,

I was asked by a customer to create a scheduled weekly report detailing work that had been completed in the previous week (Monday to Friday) I figured they might lose the report or something might happen to stop the scheduler from running it, and I didn't want to have to modify my script to work out date ranges for the selection criteria if I ran the report later in the current week.  So the script below works with a variable date range based on a calculation of the current weekday. The dates are converted to a varchar(12) to truncate timestamps.

However, this is only good if you run the report on a weekday (Mon-Fri), it kinda  falls over if you run it on a weekend as it will include weekend dates which is easily fixed by filtering the dates to ignore weekdays 1 & 7.  But then, who works weekends?

Total article views: 125 | Views in the last 30 days: 2
 
Related Articles
FORUM

get weekday in mdx

get weekday from dim value (string? not date)

ARTICLE

Finding the Correct Weekday Regardless of DateFirst

In this article, learn how to get the correct weekday regardless of the DateFirst setting on your se...

FORUM

TSQL copy data in weekdays

TSQL copy data in weekdays

SCRIPT

UDF_GET_NEXT_WEEKDAY

A simple way of getting the next weekday's dates...

Tags
miscellaneous    
 
Contribute