Thursday, 2 February 2017

Query to Print 1 to 100 in SQL Server without using Loops.

Query to Print 1 to 100 in SQL Server without using Loops.

There are several ways to achieve above scenario in SQL Server. Here I will explain using Recursive CTE.
WITH RESULTS
AS

(
   SELECT 1 SequenceNo
   UNION ALL
   SELECT SequenceNo+1 from RESULTS WHERE SequenceNo < 100
)

SELECT * from RESULTS

 

No comments:

Post a Comment