Looking for Insert ideas using SPROC

  • I have a table (gtrs_v15) with a dateTime field named v15, that via a sproc using parameters (@startV15 and @endV15)I would like to insert a dateTime record into, for every 15 minutes between @startDateTime and @endDateTime.

    Like startV15 = '2003-12-01 00:00:00'

    endV15 = '2003-12-02 00:00:00'

    would result in:

    v15

    2003-12-01 00:15:00

    2003-12-01 00:30:00

    2003-12-01 00:45:00

    2003-12-01 01:00:00

    2003-12-01 00:15:00

    and so on:

    Any ideas?

  • Something like this maybe?

    declare @startV15 datetime, @endV15 datetime, @currentV15 datetime
    

    set @startV15 = '2003-12-01 00:00:00'
    set @endV15 = '2003-12-02 00:00:00'

    -- Add the first 15 minute interval to the start datetime
    set @currentV15 = dateadd(mi, 15, @startV15)
    while @currentV15 < @endV15
    begin
        insert gtrs_v15 values (@currentV15)
        set @currentV15 = dateadd(mi, 15, @currentV15)
    end

    Took a couple of seconds to run using the example dates given though.

    Cheers,

    mia

    Life moves pretty fast. If you don't stop and look around once in a while, you could miss it.


    Cheers,
    mia

    Life moves pretty fast. If you don't stop and look around once in a while, you could miss it.

  • quote:


    Something like this maybe?

    declare @startV15 datetime, @endV15 datetime, @currentV15 datetime
    

    set @startV15 = '2003-12-01 00:00:00'
    set @endV15 = '2003-12-02 00:00:00'

    -- Add the first 15 minute interval to the start datetime
    set @currentV15 = dateadd(mi, 15, @startV15)
    while @currentV15 < @endV15
    begin
        insert gtrs_v15 values (@currentV15)
        set @currentV15 = dateadd(mi, 15, @currentV15)
    end

    Took a couple of seconds to run using the example dates given though.

    Cheers,

    mia

    Life moves pretty fast. If you don't stop and look around once in a while, you could miss it.


    Thanks mia - that's exactly what I was looking for

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

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