?
Solved

Mass update parts of dates in orders table

Posted on 2004-10-18
5
Medium Priority
?
220 Views
Last Modified: 2006-11-17
I need to update various dates in an orders table to make them logically consistent before we can upgrade the system to the new version, for example the membership card expiry date should be the anniversary of the date they joined. I think I can do this with a CURSOR and iterate through all records 'fixing' the dates - but there are many thousands of orders and my understanding of CURSORS is that they are very slow and use a lot of resources.

Is there another way to carry out this type of update?
0
Comment
Question by:catprotection
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 12337728


UPDATE <YOUR_TABLE>  SET EXPIRY_DATE = DATEADD( YEAR, 1, JOINED_DATE )


itsvtk
0
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 12337755
Hi,

You can use my above query to get your requirement done.... Here is the artical on Date Funtions...

http://www.databasejournal.com/features/mssql/article.php/3076421

itsvtk
0
 

Author Comment

by:catprotection
ID: 12337806
itsvtk - that will set ALL dates to be an anniversary of the JOINED_DATE rather than on a row by row basis?

Each order has its own JOINED_DATE and EXPIRY_DATE and so i need to compare each entry to establish what the correct date should be for that order before setting the date based on it
0
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 12337843
My Query will set on row by row basis only.....

if you have any doubts, take a backup of your table and run my query and check the data....

itsvtk :)
0
 
LVL 14

Accepted Solution

by:
Thandava Vallepalli earned 1000 total points
ID: 12337884
ok ..... try my new query... it will set the expirey_date only when the difference between the dates are not exactly one year....


UPDATE <YOUR_TABLE>  SET EXPIRY_DATE = DATEADD( YEAR, 1, JOINED_DATE )
WHERE DATEDIFF( YEAR, JOINED_DATE, EXPIRY_DATE ) <> 1


itsvtk

0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question