The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
When I run the SQL query on my desktop machine, its fine. No errors or anything. However, when I execute the same code on the server that will be running it, it fails.
I’ve determined this is the section of SQL causing the issue. DateOfRun is a DateTime field.
,(SELECT intField
FROM tableA
WHERE RowIdentifier= ParentTable.RowIdentifier
AND DateOfRun = Convert(Varchar(10),ParentTable.OfferOutcomeDateTime,120)) AS Days
Why would this work on one machine, but not the other?
That’s definitively odd and likely to do with regional settings but its like the old joke
So don’t do that. Do this instead
Its the best way to go see Thomas’ answer to Most efficient way in SQL Server to get date from date+time?
Then it will work regardless of regional settings because it never gets represented as a string