micrsoft, sql server, 2000, trigger to add minutes to dates

Posted on 2007-08-07
Last Modified: 2013-11-05

I have a requirement  ,have table 1with the folowing following data

Priority      days
10      365
20      182
30      92
40      62
50      28
60      7
70      1

in my other table (work)is a field called startdate and priority,if i insert a record into this table then it must take the startdate and add the days based on each priority


woid              startdate                       priority                  enddate
1000                8-7-7                               70                     8-8-7     ( 8-7-7  +1 day)
1002                8-7-7                               10                    8-8-8    ( 8-7-7  +365 days)

can anybody help will with this pls
Question by:rutgermons
    LVL 25

    Expert Comment

    case priority when 70 then startdate + 1 when 10 then startdate + 10 end
    LVL 25

    Accepted Solution

    I put 10 where it hat to be 365

    case priority when 70 then startdate + 1 when 10 then startdate + 365 end

    Author Comment

    how does it display in triiger form?
    LVL 25

    Expert Comment

    with my code you can vary the result

    For triggering you must know very well what you want in case of insert, update or delete. Select from table 'inserted' to get your new value

    CREATE TRIGGER trg_Mytalbe1_insert ON Mytalbe1
    insert ..... select case priority when 70 then startdate + 1 when 10 then startdate + 365 end
          FROM inserted


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I recently came across an interesting Question In EE ( and was puzzled about how to achieve that using SSIS out of the box tasks, which was i…
    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now