0

TABLES:

tblEmployee - EmployeeId, EmployeeName    
tblActivity - EmployeeId, AppraisalId

Column AppraisalId is of datatype int and has either values 0-2 or NULL.

The Selected values of the 2 dropdowns provide the parameters for the stored procedure.

A user can search for records of all employees or just any one. Similarly, for all, none or any one type of appraisal.

What should I do if I have to search only for records that have AppraisalId as NULL. The query works fine otherwise.

ASPX:

<asp:dropdownlist id="ddlemployee" runat="server" appenddatabounditems="true">
 <asp:listitem text="--All--" value="0"/>
</asp:dropdownlist>

<asp:dropdownlist id="ddlappraisal" runat="server" appenddatabounditems="true">
 <asp:listitem text="--All--" value="-1"/> 
  <asp:listitem text="None"/>   //not sure what value this should have
  <asp:listitem text="Excellent" value="2"/>
  <asp:listitem text="Average" value="1"/>
  <asp:listitem text="Poor" value="0"/>
</asp:dropdownlist>

SQL:

alter procedure getdata
@EmployeeId int
@AppraisalId int
as
begin
 set nocount on;
 if  @EmployeeId = 0
 set @EmployeeId = null


 select e.employeename,a.appraisalid
 from tblemployee e
 left join tblactivity a on 
 ( e.employeeid = a.employeeid and 
   (e.employeeid = @Employeeid or @Employeeid is null) and
   (a.appraisalid = @AppraisalId or @AppraisalId = -1)       
 )
end

1 Answer 1

1

You could provide a value of -2 for None option:

<asp:listitem text="None" value="-2"/>

And modify the query (showing only select here, the rest stays the same):

select e.employeename,a.appraisalid
 from tblemployee e
 left join tblactivity a on 
 e.employeeid = a.employeeid and 
   (e.employeeid = @Employeeid or @Employeeid is null) and
   (a.appraisalid = @AppraisalId or @AppraisalId = -1
       or (@AppraisalId = -2 and a.appraisalid is null)       
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.