WELCOME TO THE COMMUNITY
find what you are looking for or ask a new question
Home > Forum > Latest posts

latest posts

MVP
In reply to: Igor Sobolewski

Hello there :)

I have the following error, attached.

Best Regards

Could you provide also screenshots from configuration, and Webcon version?
(webcon doesn't have great support for all parts of SQL and CTE's are one of them - that's why I'm using functions, to avoid webcon trying to parse CTE).

MVP

Hi
I'd go with creating a function for that task, and would use recursive CTE.

Function like this:

CREATE FUNCTION dbo.generate_date_range(@start_date DATE, @end_date DATE)
RETURNS @DateRange TABLE (DateValue DATE)
AS
BEGIN
WITH DateRange AS (

SELECT CAST(@start_date AS DATE) AS DateValue
UNION ALL

SELECT DATEADD(day, 1, DateValue)
FROM DateRange
WHERE DateValue < @end_date
)

INSERT INTO @DateRange(DateValue)
SELECT DateValue
FROM DateRange OPTION (MAXRECURSION 1000) -- Option could be set to 0, but I'd rather avoid unintentional infinity loop :)

RETURN;
END

Later inside webcon use it like that:
select * from generate_date_range('2024-01-01', '2024-01-10')