question

siera_gld avatar image
siera_gld asked

Force Week End Dates if no data exists

I am trying to force results for every week , now the names may not have results for specific weeks due to vacation and such, in that case I want to display "0" This should be pretty straight forward but I am not having luck... Snippet SELECT DISTINCT LastDateOfWeek INTO #weeks FROM McKinsey.dbo.Calendar WHERE LastDateOfWeek > =(SELECT DATEADD(DAY,0,DATEDIFF(DAY,0,DATEADD(DAY,7-DATEPART(DW, getdate()), getdate()-84)))) AND LastDateOfWeek t-sqldatesinner joinleft joinweeks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered
Your `WHERE` clause is forcing the query to behave as an `INNER JOIN`. If you change it to account for NULL values, you might get the rows you're looking for: `WHERE r.Name IS NULL OR r.Name = @Name`
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.