答案 0 :(得分:0)
如果我理解正确,那就简单了:
; WITH CTE AS (
SELECT UserName,
Case WHEN Workflow1 = '' THEN 0 ELSE 1 END AS Workflow1,
Case WHEN Workflow2 = '' THEN 0 ELSE 1 END AS Workflow2,
Case WHEN Workflow3 = '' THEN 0 ELSE 1 END AS Workflow3,
Case WHEN Workflow4 = '' THEN 0 ELSE 1 END AS Workflow4
FROM Table )
SELECT UserName,
Workflow1,
Workflow2,
Workflow3,
Workflow4,
CAST (Workflow1 AS INT) +
CAST (Workflow2 AS INT) +
CAST (Workflow3 AS INT) +
CAST (Workflow4 AS INT) AS Count_Avail
FROM CTE AS C
INNER JOIN Table AS T ON C.UserName = T.UserName