• Here is an exampe of generating a range of numbers form an existing tally table or function with numbers starting at 1.

    -- Get a range of numbers based on a tally table, the range can be 20bits wide

    -- (1048576 positions) in this example.

    declare @min-2 bigint, @max-2 bigint;

    select @min-2 = 1000000000, @max-2 = 1000000200;

    select top (@max - @min-2 + 1) (@min - 1) + N from dbo.tally20b;

    Even with a 12 bit tally table you can generate ranges of 4096 numbers at any position in the bigint range. Creating intervals is no more then adding a multiplyer (see below):

    -- Get a range of numbers based on a tally table, the range can be 20bits wide

    -- (1048576 positions) in this example. An interval of 10 is used.

    declare @min-2 bigint, @max-2 bigint;

    select @min-2 = 1000000000, @max-2 = 1000000200;

    select top (@max - @min-2 + 1) @min-2 + (10 * (N - 1)) from dbo.tally20b;