Solved

ON DUPLICATE KEY UPDATE IF

Posted on 2014-12-01
2
204 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
Comment Utility
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
Comment Utility
Thank you Gary!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

762 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

10 Experts available now in Live!

Get 1:1 Help Now