Solved

Mass update parts of dates in orders table

Posted on 2004-10-18
5
215 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

856 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