Solved

ON DUPLICATE KEY UPDATE IF

Posted on 2014-12-01
2
209 Views
Last Modified: 2014-12-01
I am  trying to insert or update depending on criteria. On the update I want to make sure before the update if (one Datetime value is < than the other Datetime value. then update - if not - dont do anything how do I do that

INSERT INTO Temp_MyTools(Select 0 as 'id', ToolType,SerialNumber,MAX(UploadDate) as 'FUploadTime', Cast('2012:01:01 12:00:00 AM'as DateTime) AS 'HUploadTime',  LocationID as 'DefaultLocationIndex', 1 as 'Qty' FROM Inventory_SerializedAssets Where LocationID in('" + locationIndex + "') GROUP BY SerialNumber)  ON DUPLICATE KEY UPDATE IF(FUploadTime <VALUES(FUploadTime)), FUploadTime = VALUES(FUploadTime);

Open in new window

0
Comment
Question by:r3nder
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40474684
This should be it if I'm following your question right

...ON DUPLICATE KEY UPDATE FUploadTime = IF(FUploadTime< VALUES(FUploadTime), VALUES(FUploadTime),FUploadTime);

Open in new window

0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40474694
Thank you Gary!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

778 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