SQL Server:SELECT CASE返回NULL

时间:2016-04-01 06:30:16

标签: sql sql-server

我尝试if lcase(Range("B5").Value) = "active" then select case ucase(nationality) case "DT", "AT", "CH" With ActiveWorkbook.Sheets("PostStayEmail_DE") Set rng = .Range("A1:B30").SpecialCells(xlCellTypeVisible) 'do something End With case "IT" With ActiveWorkbook.Sheets("PostStayEmail_IT") Set rng = .Range("A1:B30").SpecialCells(xlCellTypeVisible) 'do something End With case else 'do thing if no matches end select else 'do stuff when B5 is not 'Active' end if ,如果SELECT ='',那么我希望结果返回为{{1} }}

例如:

CurrencyCode

可以吗?

1 个答案:

答案 0 :(得分:5)

使用CASE WHE... THEN... ELSE... ENDNULLIF

有两种可能性
SELECT CurrencyCode,
NULLIF(CurrencyCode,''),
CASE
    WHEN CurrencyCode = ''
    THEN NULL
    ELSE CurrencyCode
END
FROM Contract