Null values ​​in the Date column returned as 1900/01/01 when executing a SELECT statement

The [PAYOFF DATE] column has several empty values ​​and some values ​​in the format mm / dd / yy.

I need to replace '/' with '-' and return the date as yyyy-mm-dd. The following query does this. The problem is that for all empty values ​​I get the results as 1900-01-01.

Is it possible to replace 1900-01-01 with zero and return other valid date values, as in the format yyyy-mm-dd?

I am using SQL Server.

SELECT
cast(replace(a.[PAYOFF DATE],'/','-') as date) 
FROM MTG a
+4
source share
1 answer

, . , mm/dd/yyyy, DATE.

SELECT cast(a.[PAYOFF DATE] AS DATE) 
FROM MTG a 

1900-01-01, Date, String , , , NULL.

, . 1900-01-01 - , SQL- , Date .

sql, - .

SELECT cast(NULLIF(a.[PAYOFF DATE],'') AS DATE) 
FROM MTG a 
+6

Source: https://habr.com/ru/post/1535816/


All Articles