Quantcast
Channel: Questions in topic: "tally"
Viewing all articles
Browse latest Browse all 10

Calculate Date Based on Start and End Date plus Existence of Specific Character in Tally Column

$
0
0

Hi there,

I am trying to create a list of dates which correlate to a specific weekday (Wednesdays in this case), where I only have the start date, end date, and what can be described as some sort of tally column. I want to be able to use this list of dates in an SSRS report. The dates reflect the occurrence of a lesson taking place, and I will eventually be adding the room of where the lesson takes place but need to cross this bridge first.

The start date is 6th September 2017, the end date is 24th January 2018, and the tally column is a string a 1's:

1111111_11111111__111

There is a total of 21 characters in the above string, which represents the range of 21 weeks between the start and end dates. I suspect that the database structure was designed in this way to conserve disk space. The presence of a 1 in the tally column means that a lesson is scheduled to take place on the correlated date. The underscores in the tally column are not present in the actual tally column, but I've entered them to highlight the fact that it's just a space, which denotes a week/week where no lessons take place.

Those weeks are week 8, for 25th October 2017 and weeks 17 and 18 to represent the Christmas break for weeks 27th December 2017 and 3rd January 2018.

What I am after is that I want to generate a date for the weeks where the position of the string tally column contains a '1', and to not generate a date where there is an underscore (i.e. I want to ignore the weeks which are holidays).

I have been able to generate the dates of interest by tweaking the code contained in the post by kherlad69 at this link - https://www.sqlservercentral.com/forums/topic/get-particular-day-between-two-dates (post #1736478 - thank-you!), but I am not able to exclude the holiday weeks. I have tried to use CROSS APPLY to achieve what I want, but didn't get very far (I probably need a LEFT OUTER JOIN), so am asking if anybody knows how to accomplish what I'm after.

Thanks in advance for your help,

Andrew


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images