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