Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-09-08 : 07:26:01
|
| david writes "I have a table that has a date field in it for when each record was created. I need to update a stauts feild to the value new or old based on the difference in days of the current date and the date filed value. if the difference is less that 22 days it is new if the record is more that it is old. I would like to do this with a trigger to execute at any time the table is modified. I am using sql 2000 xp and aspthanks dj" |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2003-09-08 : 08:08:26
|
| search for "INSTEAD OF TRIGGER"some samples here should get you moving....you also need some code involving the DATEDIFF function.again searching .... will throw up some other examples.... |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-09-08 : 08:21:57
|
Actually, it should try not to store this status inside the table, it can be calculated while retreiving the rows from the table. You could compute this status in a view or a stored procedure. And if you really want to do it, you don't really need a trigger. It can be accomplished using computed columns:create table #foo(cola datetime not null,colb as (case when datediff(d, getdate(), cola) > 0 then 'Overdue' else 'not due' end))Owais Make it idiot proof and someone will make a better idiot |
 |
|
|
|
|
|