Thursday, 22 October 2009

Table to Insert Incremental Values

Objective: To populate multiple incremental values in table.

Create Table test (val float)
insert into test values (0.001)
declare @t float
select @t = max(val) from test
Insert into test
select val + @t from test

Or
DECLARE @idt float
SET @idt = 0
WHILE (@idt < 10)
BEGIN
SELECT @idt = @idt + 0.001
insert into tablename (columnname)
select @idt
END

or

DECLARE @idt int
SET @idt = 0
WHILE (@idt < 100)
BEGIN
SELECT @idt = @idt + 1
insert into tablename (columnname)
select @idt
END

No comments:

Post a Comment