A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi Arkiboys,
The script below creates a date table with you can use to check your missing dates. I created the #temp table to represent your table.
DECLARE @Startdate date = CAST('20220101' as datetime)
DECLARE @Enddate date = CAST('20220110' as datetime)
DROP TABLE IF EXISTS #temp
CREATE TABLE #temp
(
_year int,
_month int,
_day int
)
INSERT INTO #temp VALUES (2022,1,1)
INSERT INTO #temp VALUES (2022,1,2)
INSERT INTO #temp VALUES (2022,1,4)
INSERT INTO #temp VALUES (2022,1,5)
INSERT INTO #temp VALUES (2022,1,6)
INSERT INTO #temp VALUES (2022,1,9)
INSERT INTO #temp VALUES (2022,1,10)
;WITH DateTable
AS
(
SELECT @Startdate AS [date]
UNION ALL
SELECT DATEADD(dd, 1, [date])
FROM DateTable
WHERE DATEADD(dd, 1, [date]) <= @Enddate
)
SELECT [date] FROM DateTable
EXCEPT
select datefromparts(_year, _month, _day) FROM #temp
OPTION (MAXRECURSION 0)