Show empty string when date field is 1/1/1900

前端 未结 7 778
时光取名叫无心
时光取名叫无心 2020-12-31 09:36

I\'m querying a database like so:

SELECT DISTINCT 
CASE WHEN CreatedDate = \'1900-01-01 00:00:00.000\' THEN \'\' ELSE CreatedDate END AS CreatedDate
FROM Lit         


        
7条回答
  •  心在旅途
    2020-12-31 09:57

    An alternate solution that covers both min (1/1/1900) and max (6/6/2079) dates:

    ISNULL(NULLIF(NULLIF(CONVERT(VARCHAR(10), CreatedDate, 120), '1900-01-01'), '2079-06-06'), '').
    

    Whatever solution you use, you should do a conversion of your date (or datetime) field to a specific format to bulletproof against different default server configurations.

    See CAST and CONVERT on MSDN: https://msdn.microsoft.com/en-us/library/ms187928.aspx

提交回复
热议问题