Tuesday, 10 January 2017

SQL – Generate decimal numbers sequence for particular number range

Friends,
Sometimes we need mathematical assistance in SQL for such queries. Same here, it helps me to find challenging in all the way.
Some of my friends helps me out to crack the records for my query, Here I am sharing simple solution for this,
;WITH cte
     AS (SELECT Cast(-77 AS NUMERIC(22, 3)) AS num –Min value from your data
         UNION ALL
         SELECT Cast(num + 0.00001 AS NUMERIC(22, 5))
         FROM   cte
         WHERE  num < Cast(89 AS NUMERIC(22, 5))) — Max value from your data
SELECT *
FROM   cte
OPTION (maxrecursion 0) 
Try it 🙂

No comments:

Post a Comment