Prevent this outcome:
DECLARE @date_today DATE;
SET
@date_today = '2022-12-12'; DECLARE @date_weekago DATE;
SET
@date_weekago = '2022-12-05'; WITH duplicate AS (
With this outcome:
DECLARE @date_today DATE;
SET @date_today = '2022-12-12';
DECLARE @date_weekago DATE;
SET @date_weekago = '2022-12-05';
WITH duplicate AS (
My DECLARE SET order is like this due dynamic content being added to the query.
Maybe this doesn't suit all cases, such as multiple set at same line, but WITH and DECLARE at new line seems a must to me
Prevent this outcome: DECLARE @date_today DATE; SET @date_today = '2022-12-12'; DECLARE @date_weekago DATE; SET @date_weekago = '2022-12-05'; WITH duplicate AS (
With this outcome: DECLARE @date_today DATE; SET @date_today = '2022-12-12'; DECLARE @date_weekago DATE; SET @date_weekago = '2022-12-05'; WITH duplicate AS (
My DECLARE SET order is like this due dynamic content being added to the query.
Maybe this doesn't suit all cases, such as multiple set at same line, but WITH and DECLARE at new line seems a must to me
I also added @andig CROSS JOIN