December 13, 2006 at 4:52 pm
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.
December 13, 2006 at 10:44 pm
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
December 14, 2006 at 8:49 am
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:
publicationdate | NoOfDays |
2006-12-13 10:44:53.317 | 1 |
2006-12-12 10:44:53.317 | 2 |
2006-11-23 10:44:53.317 | 20 |
2006-11-19 10:44:53.317 | 20 |
Lowell
December 15, 2006 at 2:42 am
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