I want to get the 5 dates of the past week(LV). I have one tabla1
where the dates are recorded from Monday to Friday, but for example if there were no records on Tuesday I need that when SELECT
I do the table it returns that date but as a result 0
or null
but it returns it, what I don't want is this is Monday(date), Wednesday(date), Thursday(date), Friday(date), that is, Tuesday is missing here because there were no records.
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0)
With this select I can know where the last week starts (date) and with the following I can get the last day (date):
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6-2)
Regardless of the fact that if a registered date is missing, I want it to return the 5 dates of the week, how could I do this or any other suggestion?
What you could do is a table of days of the week, and join it against your query, that way, if something comes up null, you'd know there's nothing.
Given the table DaysWeek
could you do the following
That way, you will always show the days.
This is how I get the days of the week that there were records in the past week.