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

前端 未结 7 766
时光取名叫无心
时光取名叫无心 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 10:00

    Two nitpicks. (1) Best not to use string literals for column alias - that is deprecated. (2) Just use style 120 to get the same value.

        CASE 
          WHEN CreatedDate = '19000101' THEN '' 
          WHEN CreatedDate = '18000101' THEN '' 
          ELSE Convert(varchar(19), CreatedDate, 120)
        END AS [Created Date]
    

提交回复
热议问题