I have a table into which I want to convert a string to datetime and insert. However I am getting a conversion failed error
INSERT INTO CUSTOMERS_PURCHASE([PURCHASE_DATE], [PURCHASE_TIME], [PURCHASE_CITY])
SELECT CAST( '03-January-2023' AS DATETIME2) AS PURCHASE_DATE,
[PURCHASE TIME] AS PURCHASED_TIME, [PURCHASE_CITY] FROM CUSTOMERS_INDIA
Error: Conversion failed when converting date and/or time from character string.
Can I get some advice/ help on how I can resolve this? I am using Microsoft SQL
1条答案
按热度按时间vwkv1x7d1#
Use
try_convert()
... It will return a NULL rather than throwing an error if the conversion failsResults