An alternative to using a CASE statement is to use the COALESCE function which returns the first non-NULL argument.
SELECT
COALESCE(NULLIF(LastName,'') + ',' + NULLIF(FirstName,''), UserName)
FROM
MyTable
Note:- It's important to use the + to concat the columns as this will return NULL if any column contains null. The CONCAT function will return a value that contains the non-NULL parts.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…