是否有更快的替代方法来检查SQL语句中CASE语句中的SELECT语句是否为空?

时间:2014-04-02 11:42:34

标签: sql-server select case isnull case-statement

此案例陈述是否有更快的版本?

CASE
 WHEN (SELECT STATEMENT) IS NOT NULL
 THEN (SELECT STATEMENT)
 ELSE 0
END AS [Variable Name]

SELECT STATEMENT不会从第2行更改为第3行。

谢谢!

2 个答案:

答案 0 :(得分:0)

更快地输入...

isnull(statement, 0)

答案 1 :(得分:0)

WITH cte
AS
(
    SELECT co11
    FROM ...
)
SELECT ISNULL(cte.col1, 0) as [Variable Name]
FROM cte