Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding milliseconds to a DateTime in TSQL INSERT INTO

I'm doing an INSERT INTO query in order to initialize a new table. The primary key is RFQ_ID and Action_Time

How could add 1 millisecond to each Action_Time on a new record in order to avoid "Violation of PRIMARY KEY constraint"

INSERT INTO QSW_RFQ_Log
            (RFQ_ID, Action_Time, Quote_ID)
SELECT     RFQ_ID, GETDATE() AS Action_Time,  Quote_ID, 'Added to RFQ on Initialization' AS Note
FROM         QSW_Quote
like image 688
DavRob60 Avatar asked Apr 12 '10 20:04

DavRob60


1 Answers

Adding only 1 millisecond wont work as the datetime values in SQL are rounded to increments of .000, .003, or .007 second. SO if you are going to add only 1 millisecond in any date time value there shall not be any impact on the original datetime.

You need to add minimum 2 milliseconds in the datetime so that the new datetime can be rounded to .003 and your implemnentations will work.

like image 66
Abhishek Gahlout Avatar answered Oct 09 '22 18:10

Abhishek Gahlout