• drew.allen (8/25/2016)


    JALLYKAMOZE (8/25/2016)


    CREATE TABLE DELAYSECONDS(

    ProgramID INT, ID INT, ContractHeaderID INT, ContractStartTime TIME, ProgramStartTime TIME ,ContractDetailFirstDay INT ,ProgramFirstDay INT, DelaySeconds INT)

    INSERT INTO DELAYSECONDS

    VALUES (625, 625, 115278, '18:00:00', '18:00:00', 2, 2, 0),

    (623, 623, 115279, '8:00:00', '15:05:00', 1,NULL, 0),

    (624, 624, 115280, '18:00:00', '19:00:00', 7, 7, 0),

    (625, 625, 115281, '18:00:00', '18:00:00', 2, 2, 0),

    (625, 625, 115282, '19:00:00', '18:00:00', 2, 2, 3600)

    see my data above,

    i want the delayseconds field populated

    the logic is below:

    lets get the time difference between the

    contractdetailfirstday - programdetailfirstday = a

    a*24(hrs of the day)*60(minutes in the hour)*60(seconds in the minute) =b

    lets get the time difference between the time

    contractdetailstarttime-programstarttime (inseconds) =c

    b+c = d 'delayseconds'

    if (d>0) then return d

    else o

    does this make sense?

    No, it doesn't make sense. Using DATEDIFF() as was already mentioned makes sense. The built-in functions are generally going to be much more efficient and accurate than anything that you code (especially if you're going to use cursors).

    pls assist as this is due today.

    thanks

    You do realize that we are all volunteering our time and effort. If you need something done in a specific timeline, then you should look into hiring a contractor.

    Drew

    thanks you for your response.

    I learn from the footprints of giants......