Thought about creating a bit of a calendar with recursive CTE on dates. However I get the following error once running it:
Types don't match between the anchor and the recursive part in column "ddmmyyyy" of recursive query "cte_days"
Code:
WITH cte_days(n, weekd, ddmmyyyy) AS
(
SELECT
0, DATENAME(DW, '09-03-1983'), CONVERT(varchar, '09-03-1983', 10)
UNION ALL
SELECT
0 + 1, DATENAME(weekday, DATEADD(day, 1, '09-03-1983')), DATEADD(day, 1, '09-03-1983')
FROM
cte_days
WHERE
n < 10
)
SELECT *
FROM cte_days
At that I tried testing data in ddmmyyyy column running two SELECTS in the middle and it was returned accurate:
0 Saturday 1983-09-03 00:00:00.000
1 Sunday 1983-09-04 00:00:00.000
It also worked fine once creating a temp table with date column and sticking both values in there...
So can you help finding a mismatch?
Thank you.
SQL_Variant_Propertyto display the data type of an expression. CompareSELECT SQL_Variant_Property( 0, 'BaseType' ), SQL_Variant_Property( DATENAME(DW, '09-03-1983'), 'BaseType' ), SQL_Variant_Property( CONVERT(varchar, '09-03-1983', 10), 'BaseType' )andSELECT SQL_Variant_Property( 0 + 1, 'BaseType' ), SQL_Variant_Property( DATENAME(weekday, DATEADD(day, 1, '09-03-1983')), 'BaseType' ), SQL_Variant_Property( DATEADD(day, 1, '09-03-1983') , 'BaseType' );.