June 2, 2025 at 6:24 am
SELECT
[A]
--,[Date]
,
,[C]
,[D]
,[E]
FROM [Database].[dbo].[Table]
where B < 1000
AND (CheckDate >= getdate()-4 AND
CheckDate < getdate())
EXCEPT
SELECT
[A]
--,[Date]
,
,[C]
,[D]
,[E]
FROM [Database].[dbo].[Table]
where B < 1000
AND (Date >= getdate()-6 AND
Date < getdate()-1)
Every week the date column will have the current date.
How do I add back the Date column into the above result set.
June 2, 2025 at 1:03 pm
Uncomment it? (remove the double hyphens before ,[Date])
Does that code actually work with the extra comma?
June 2, 2025 at 1:28 pm
Add the date column after the except is excecuted along with the rest of the columns - A,C,D,E
June 3, 2025 at 3:01 am
For someone with as much experience here as you seem to have, where's the explanation of what you're trying to do? You know, in plain English.
June 3, 2025 at 3:01 am
For someone with as much experience here as you seem to have, where's the explanation of what you're trying to do? You know, in plain English.
June 3, 2025 at 3:45 am
I am trying to include the datetime column back into the result set after doing the except.
June 3, 2025 at 5:51 am
Try something along these lines ...
WITH cteDiff (
SELECT A, C, D, E
FROM [Database].dbo.[Table]
WHERE B < 1000
AND ( CheckDate >= GETDATE() -4
AND CheckDate < GETDATE())
EXCEPT
SELECT A, C, D, E
FROM [Database].dbo.[Table]
WHERE B < 1000
AND ( Date >= GETDATE() -6
AND Date < GETDATE() -1 )
)
SELECT src.A, src.[Date], src.C, src.D, src.E
FROM cteDiff AS xcpt
JOIN [Database].dbo.[Table] AS src
ON xcpt.A = src.A
AND xcpt.C = src.C
AND xcpt.D = src.D
AND xcpt.E = src.E
WHERE src.B < 1000
AND ( src.CheckDate >= GETDATE() -4
AND src.CheckDate < GETDATE())
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply