SQL SERVER – Generate Incremented Linear Number Sequence

Just a day ago, I received interesting question on this blog. Read original question here. This is very good question and after reading this question I quickly wrote small script as answer. Let us see the question and answer together.

Q. How can we generate incremented linear number in sql server as in oracle we generate in via sequence?

1
2
3
4
5
6
7
8
9

A. Run following script which will generate output in sequence, which will generate output as you requested.

DECLARE @idt INT
SET @idt = 0
WHILE (@idt < 100)
BEGIN
SELECT @idt = @idt + 1
PRINT @idt
END

Reference : Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)

SQL Scripts, SQL Server
Previous Post
SQL SERVER – Sharpen Your Skills: Joins, Groupings, and Data Types
Next Post
SQL SERVER – Shrinking Truncate Log File – Log Full – Part 2

Related Posts

Leave a Reply