Solved

Mass update parts of dates in orders table

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

914 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

18 Experts available now in Live!

Get 1:1 Help Now