Print from 1 to 100 sequentially with out using cursor, while or any other iterative loop.
Ans:
We can achieve this by using Common Table Expression (CTE). CTE, are a new construct introduced in Microsoft SQL Server 2005 that offer a more readable form of the derived table that can be declared once and referenced multiple times in a query. Moreover, CTEs can be recursively defined, allowing a recursive entity to be enumerated without the need for recursive stored procedures.
We can achieve the above using recursive CTE:
Please execute the below statements:
WITH Series (Number)
AS
(
SELECT 1
UNION ALL
SELECT Number +1 FROM Series
WHERE Number < 100 )
Select * from Series
And see the result

Ans:
We can achieve this by using Common Table Expression (CTE). CTE, are a new construct introduced in Microsoft SQL Server 2005 that offer a more readable form of the derived table that can be declared once and referenced multiple times in a query. Moreover, CTEs can be recursively defined, allowing a recursive entity to be enumerated without the need for recursive stored procedures.
We can achieve the above using recursive CTE:
Please execute the below statements:
WITH Series (Number)
AS
(
SELECT 1
UNION ALL
SELECT Number +1 FROM Series
WHERE Number < 100 )
Select * from Series
And see the result

Comments