我正在设置销售人员参数,在SalesID列中需要一个NULL值,但在“显示名称”列中需要说未设置。显示中有NULL值,但我要改用SalesID。
SELECT SalesID,
ISNULL(DisplayName, SalesID) AS DisplayName
FROM SalesTable
答案 0 :(得分:1)
用例when和COALESCE()
SELECT SalesID,
case when DisplayName is null and SalesID is null then 'Not Set'
else COALESCE(DisplayName,SalesID) end AS DisplayName
FROM SalesTable
答案 1 :(得分:1)
考虑到您正在使用SQL SERVER,可以扩展COALESCE函数-
@Parcelize
data class SavedState(val isLoading: Boolean = false): BaseSavedState()
答案 2 :(得分:0)
这是您想要的吗?
SELECT SalesID,
COALESCE(DisplayName, 'Not Set') AS DisplayName
FROM SalesTable
答案 3 :(得分:0)
SELECT SalesID,
CASE WHEN (DisplayName IS NULL AND SalesID IS NULL) THEN 'Not Set' ELSE DisplayName END AS DisplayName
FROM SalesTable