使用isnull和coalesce重写SQL查询 [英] Rewrite SQL query using isnull and coalesce

查看:121
本文介绍了使用isnull和coalesce重写SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rewrite below incorrect statement in two ways using isnull and coalesce
select * from Test_Table where Test_ID=null





我尝试过:





What I have tried:

rewrite below incorrect statement in two ways using isnull and coalesce
select * from Test_Table where Test_ID=null

推荐答案

SELECT    TOP 10 *
FROM      Google
WHERE    (NULL, Coalesce) IN SearchTerms


不清楚你的内容问题是。但这里有一个关于如何使用COALESCE和ISNULL函数的例子。



Not clear what your question is. But here an example on how to use COALESCE and ISNULL function.

--if first column/Test_ID is null, use value from second column which is ''
SELECT    *
FROM      Test_Table 
WHERE    COALESCE(Test_ID, '') = ''

--if Test_ID is null, return ''
SELECT    *
FROM      Test_Table 
WHERE    ISNULL(Test_ID,'') = ''



在这里你可以找到更多关于上述功能的信息。

COALESCE(Transact-SQL)| Microsoft Docs [ ^ ]

在SQL Server中的COALESCE和ISNULL之间进行决策 [ ^ ]


这篇关于使用isnull和coalesce重写SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆