Solved

ON DUPLICATE KEY UPDATE IF

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

790 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