running getdate

  • Hello,

    1)  days counted from the "GETDATE" already inserted, and returning an integer in that column, automatically, all the time until after a specified number of days (say 20 for example), the relevant table row will be automatically deleted, replaced by another insert (row) to start again and this repeated many times.                   

                                                                           and/or,

     

    2)  (GATEDATE()) running all the time in a column, to automatically always have the present date and time available in that column when opening the table.

     

    One or the other will give something “ticking” continuously within the table column , initiated by an insert in the row , which automatically activate (getdate()).

     

    Any ideas of how to ? Cheers and thanks in advance.Yves.

  • You can add no of days as calculated column..

    See the following ex:

    drop table #test

    Create table #test (publicationdate datetime default getdate(), NoOfDays as datediff(dd, publicationdate, getdate() ))

    insert into #test

    select getdate()-1

    insert into #test

    select getdate()-2

    select * from #test

    MohammedU
    Microsoft SQL Server MVP

  • and based off of Mohammed's example, here's the limit after 20 example:

    drop table #test

    Create table #test (

    publicationdate datetime default getdate(),

    NoOfDays as CASE WHEN datediff(dd, publicationdate, getdate()) < 20 THEN datediff(dd, publicationdate, getdate())

                ELSE 20 END)

    insert into #test

    select getdate()-1

    insert into #test

    select getdate()-2

    insert into #test

    select getdate()-21

    insert into #test

    select getdate()-25

    select * from #test

    results:

    publicationdateNoOfDays
    2006-12-13 10:44:53.3171
    2006-12-12 10:44:53.3172
    2006-11-23 10:44:53.31720
    2006-11-19 10:44:53.31720

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Seems to have some answers here...Is this will work automatically once created ? For that is what I am after, including the row deletion.

    Regards.Yves.

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

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