Solved

Mass update parts of dates in orders table

Posted on 2004-10-18
5
212 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
  • 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 250 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now