存储过程中的查询位置

时间:2017-03-03 07:11:18

标签: sql-server-2008

如果参数@ABC不为null,则在查询

中添加
@XYZ bigint,
@ABC tinyint=null

select * from WTY where 
xyz=@XYZ and ABC=@ABC 

---当@ABC为null时,它没有得到任何结果 - 仅在@ABC不为空时才需要条件进行ABC检查

1 个答案:

答案 0 :(得分:1)

使用此

@XYZ bigint,
@ABC tinyint=null

select * from WTY where 
xyz=@XYZ and ABC=@ABC OR @ABC is NULL

或者您也可以使用

select * from WTY where 
xyz=@XYZ and ABC=isnull(@ABC , ABC)
相关问题