Posted on 2014-12-01
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

Question by:r3nder
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 58

Accepted Solution

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


Author Closing Comment

ID: 40474694
Thank you Gary!

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

730 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