如果sp参数具有空值

如果sp参数具有空值

本文介绍了如果sp参数具有空值,则返回所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在存储过程中有一个select查询。它有一个参数@attendance。如果我传递'P'作为一个值,它会返回所有存在的emp名称,如果'A'则不存在。但如果我发送' '作为@attendance的值,我希望它返回所有存在的记录以及缺席。如何做到这一点?



目前我有以下where子句

select * from attend

I have a select query inside stored procedure.It has a parameter @attendance .If i pass 'P' as a value it returns all the emp names which are present and if 'A' then absent.but if i send '' as a value to @attendance i want it to return all the records present as well as absent.how to do this?

currently i have the following where clause
select * from attend

where Date=convert(datetime,'@Date',103) and
    Attend= case
    when @attendance is not null then @attendance
    else
    Attend
    end

推荐答案

where Date=convert(datetime,'@Date',103) and
    Attend= case
    when @attendance <> '' then @attendance
    else
    Attend
    end


Attend=COALESCE(@attendance ,Attend)


这篇关于如果sp参数具有空值,则返回所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:51