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 🙂

SQL Server - string_split function

In SQL Server 2016, some new functions arrived. One of them will be “string_split“. It helps to split string without writing code.
Syntax –   string_split (<string>,<separator>)
Example –
SELECT * FROM STRING_SPLIT(‘NIHAR BHALCHANDRA KULKARNI’,’ ‘)
Output –
Value
————-
NIHAR
BHALCHANDRA
KULKARNI
This is how string split into separate characters and rows.