473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Update Status column after specific date.

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
Aug 5 '08 #1
6 2533
code green
1,726 Expert 1GB
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
Aug 5 '08 #2
ck9663
2,878 Expert 2GB
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
Aug 5 '08 #3
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
Aug 13 '08 #4
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
Aug 13 '08 #5
code green
1,726 Expert 1GB
Your last question would be better re-posted.
Show your query and ask how to schedule it the way you want.
Aug 13 '08 #6
ck9663
2,878 Expert 2GB
1. Create an SP.

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

3. Monitor the results.

-- CK
Aug 13 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
2
by: Ron | last post by:
Hello, I am trying to create a page that pulls class rosters from an SQLServer database. The roster table definition is: emp_id(pk, fk), sec_id(pk, fk), reg_date and reg_status. Status can be...
4
by: jofo | last post by:
Hello all, I have project form and an hours form and related tables for each. The project table has a status flag to determine if the project is open or closed. When a user enters hours on a...
1
markmcgookin
by: markmcgookin | last post by:
This is a strange one! One minute, everything worked fine, then suddenly I don't know if i did anything, but this started happening. I have a listbox, populated with 3 values (UserID, userName...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
5
by: handoyo | last post by:
Hi all,i'm trying to show updated data in existing html td.. For example i got column that show last modified datetime,then i want to update data again,the column will changed to current time without...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.