IS NULL vs = NULL in where 子句 + SQL Server [英] IS NULL vs = NULL in where clause + SQL Server

查看:31
本文介绍了IS NULL vs = NULL in where 子句 + SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查一个值IS NULL [or] = @param(@param 为空)

How to check a value IS NULL [or] = @param (where @param is null)

例如:

Select column1 from Table1
where column2 IS NULL => works fine

如果我想用@param 替换比较值(IS NULL).这怎么办

If I want to replace comparing value (IS NULL) with @param. How can this be done

Select column1 from Table1
where column2 = @param => this works fine until @param got some value in it and if is null never finds a record.

这是如何实现的?

推荐答案

select column1 from Table1
  where (@param is null and column2 is null)
     or (column2 = @param)

这篇关于IS NULL vs = NULL in where 子句 + SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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