尝试将日期字段中的 NULL 更改为空白结果,但它一直返回日期。当我需要满足以下条件时,我会这样做:
CASE WHEN closed = 'y' THEN Date ELSE '' END
我尝试过强制转换为 varchar 和其他东西,它要么抛出错误,要么什么都不做!
You should convert it to a varchar:
CASE WHEN closed = 'y' THEN LEFT(CONVERT(VARCHAR, Date, 120), 10) ELSE '' END
See How to convert DateTime to VarChar for more information.
A column in your result can only contain one type, it can't be both a date and a text field. You could convert your date to a string providing you no longer need it to be a date like so:
CASE WHEN closed = 'y'
THEN CAST(Date AS VARCHAR)
ELSE '' END