execute insert query

  • Hi

    In my stored procedure I have a select query which gives me a number as a select, example

    'Select days from service where cid = 1', where days is the integer number.

    Now for this value(days) I want to execute a insert query into another table.

    means if days is 3 I will execute that same insert query 3 times.

    How do I take care of this in my stored procedure.

    Thanks

  • One way is:

    declare @count tinyint, @days tinyint

    select @days = days

    from service

    where cds = 1

    set @count = 1

    while @count <= <number of days> begin

    /* Insert statements in here */

    set @count = @count + 1

    end

    This will loop once for each number of days.

    Jeremy

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

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