DEV Community

Oshun123
Oshun123

Posted on

Answer: Generate a comma-separated list of numbers in a single string

The cheapest way to achieve your goal is this one (no functions, or joins to tables required):

WITH RECURSIVE NumberRanges(TheNumber,TheString) AS
(
SELECT 1 AS TheNumber,casT(1 as VARCHAR(500)) as TheString

FROM
( 
  SELECT * FROM (SELECT NULL AS X) X
) DUMMYTABLE
UNION ALL
SELECT
    TheNumber + 1 AS TheNumber,
…

Top comments (0)