Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Utilizzare TO_DATE in SQL Server 2012

SQL-Server non ha TO_DATE funzione. Devi usare convert .Vedi qui

-- Specify a datetime string and its exact format
SELECT TO_DATE('2012-06-05', 'YYYY-MM-DD') FROM dual;


-- Specify a datetime string and style 102 (ANSI format), raises an error if conversion fails
  SELECT CONVERT(DATETIME, '2012-06-05', 102);

  -- TRY_CONVERT available since SQL Server 2012 (returns NULL if conversion fails)
  SELECT TRY_CONVERT(DATETIME, '2012-06-05', 102);

Per il tuo caso specifico usa:

convert(DATETIME, '2011-11-09 00:00:00')