Connecting Tech Pros Worldwide Forums | Help | Site Map

Update Status column after specific date.

Newbie
 
Join Date: Aug 2008
Posts: 3
#1: Aug 5 '08
I have two columns in one table in database.
1. Status
2. DateCreated

Now if Todays date is one year after datecreated then change the Status to deleted.

How is it possible in SQL Server 2005. Is there any build in functionality for the same or we have to write external code ( C# ) to achive this.

Thanks

Vikas

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#2: Aug 5 '08

re: Update Status column after specific date.


I think this is OK
Expand|Select|Wrap|Line Numbers
  1. UPDATE tablename SET status = 'deleted' 
  2. WHERE datecreated < GETDATE() - 365
or this
Expand|Select|Wrap|Line Numbers
  1. UPDATE tablename SET status = 'deleted' 
  2. WHERE datecreated < GETDATE() - 12 MONTH
But double check this
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#3: Aug 5 '08

re: Update Status column after specific date.


also try:

Expand|Select|Wrap|Line Numbers
  1.       UPDATE tablename SET status = 'deleted'
  2.       WHERE datediff(yy, datecreated,GETDATE()) = 1
  3.  
Change the condition as necessary.

-- CK
Newbie
 
Join Date: Aug 2008
Posts: 3
#4: Aug 13 '08

re: Update Status column after specific date.


Quote:

Originally Posted by code green

I think this is OK

Expand|Select|Wrap|Line Numbers
  1. UPDATE tablename SET status = 'deleted' 
  2. WHERE datecreated < GETDATE() - 365
or this
Expand|Select|Wrap|Line Numbers
  1. UPDATE tablename SET status = 'deleted' 
  2. WHERE datecreated < GETDATE() - 12 MONTH
But double check this

This query is fine. I want it scheduled(automated) . There are thousand of records and daily there will be records which will qualify for this condition.
How to schedule it in SQL Server 2005 that daily Status is changed of records who satisfy the condition.

Thanks
Vikas Rijhwani
Newbie
 
Join Date: Aug 2008
Posts: 3
#5: Aug 13 '08

re: Update Status column after specific date.


Quote:

Originally Posted by ck9663

also try:

Expand|Select|Wrap|Line Numbers
  1.       UPDATE tablename SET status = 'deleted'
  2.       WHERE datediff(yy, datecreated,GETDATE()) = 1
  3.  
Change the condition as necessary.

-- CK

This query is fine. I want it scheduled(automated) . There are thousand of records and daily there will be records which will qualify for this condition.
How to schedule it in SQL Server 2005 that daily Status is changed of records who satisfy the condition.

Thanks
Vikas Rijhwani
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#6: Aug 13 '08

re: Update Status column after specific date.


Your last question would be better re-posted.
Show your query and ask how to schedule it the way you want.
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#7: Aug 13 '08

re: Update Status column after specific date.


1. Create an SP.

2. Create a job and schedule it to run once a day.

3. Monitor the results.

-- CK
Reply


Similar Microsoft SQL Server bytes