Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
SQL
where Date=convert(datetime,'@Date',103) and
    Attend= case
    when @attendance is not null then @attendance 
    else
    Attend
    end
Posted

Hi,

I hope this will help you.

SQL
where Date=convert(datetime,'@Date',103) and
    Attend= case
    when @attendance <> '' then @attendance
    else
    Attend
    end
 
Share this answer
 
Comments
pwavell 6-Jun-14 2:58am    
thanks its working.i have another query.i want to pass month,year and emp name and get whole months attendance for that employee.
Magic Wonder 6-Jun-14 3:14am    
Your welcome. You can mark this solution as accepted solution.

Also, i will suggest, first you will write your query at your own with your requirements and if in case you fail in getting the desired output then share the same in details.

Cheers
A simpler version but wroks only when passed NULL instead of ''.

SQL
Attend=COALESCE(@attendance ,Attend)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900