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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update column depending on date

Author  Topic 

starnold
Yak Posting Veteran

83 Posts

Posted - 2008-10-07 : 11:40:10
I would like to run an update on a user table but dependant on the date that they last used. So the query would be:

UPDATE USERS SET GROUPID = '9' WHERE LASTACCESSDATE = ?

How can I set a time period of lastaccessdate is older than 12 months that I can run at any point in time without having to change? Also I would like to exclude any dates that are null?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-07 : 11:44:25
Did you meant this?
UPDATE USERS SET GROUPID = '9' WHERE LASTACCESSDATE <=DATEADD(mm,DATEDIFF(mm,0,GETDATE())-12,0)
Go to Top of Page

starnold
Yak Posting Veteran

83 Posts

Posted - 2008-10-07 : 11:53:45
Thanks very much that works!
Go to Top of Page
   

- Advertisement -