Insert 1 to n records with a single SQL statement

  • I have a query where I need to insert 1 to n records where n is an integer. There is only a single field in the table and it is called 'Period' I'm looking for the most efficient SLQ possible, performance is must

    Can the SQL be in a single statement?

    On a slightly different note...I need to append records that are the result of a cartesian product. Is there a fast way to append these records or a different alternative to using a cartesian product.

    Thanks,

    Mike

  • This was removed by the editor as SPAM

  • Do not know of a way to insert multiple records without selecting from another table.

    You could create a permanent table with the maximum number of entries and then select from that table

    insert into tablename

    select num from numtable

    where num <= 20

    Other than that, only by using a loop

    declare @n int

    set @n = 0

    while n<=20

    begin

    set @n = @n + 1

    insert into tablename values (@n)

    end

    As for your second question, do not know what would be faster than standard INSERT INTO...

    would depend on table design, volume etc.

    I suppose performance would be judged by the cartesian rather than the inserts.

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply