问题描述
谁能解释一下 TSQL 中的 COALESCE 函数是如何工作的?语法如下
Can someone explain how the COALESCE function in TSQL works? The syntax is as follows
合并(x,y)
关于这个功能的 MSDN 文档很模糊
The MSDN document on this function is pretty vague
推荐答案
有人告诉我 COALESCE 的成本低于 ISNULL,但研究并未表明这一点.ISNULL 只接受两个参数,一个被评估为 NULL 的字段,以及如果它被评估为 NULL 时你想要的结果.COALESCE 将接受任意数量的参数,并返回遇到的第一个非 NULL 值.
I've been told that COALESCE is less costly than ISNULL, but research doesn't indicate that. ISNULL takes only two parameters, the field being evaluated for NULL, and the result you want if it is evaluated as NULL. COALESCE will take any number of parameters, and return the first value encountered that isn't NULL.
这里有更详尽的细节描述http://www.mssqltips.com/sqlservertip/2689/deciding-between-coalesce-and-isnull-in-sql-server/
There's a much more thorough description of the details herehttp://www.mssqltips.com/sqlservertip/2689/deciding-between-coalesce-and-isnull-in-sql-server/
这篇关于TSQL 中的 COALESCE 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!