I have a dropdownlist with following options:
<asp:DropDownList ID="ddlTaxStatus" runat="server" OnPreRender="ddlContainerStatus_PreRender">
<asp:ListItem Text="--Select--" Value="-1"></asp:ListItem>
<asp:ListItem Value="" Text="'' - Not closed"></asp:ListItem>
<asp:ListItem Value="R" Text="R - Ready to pay"></asp:ListItem>
<asp:ListItem Value="X" Text="X - Paid"></asp:ListItem>
<asp:ListItem Value="C" Text="C - Cancel"></asp:ListItem>
<asp:ListItem Value="O" Text="O - Original"></asp:ListItem>
<asp:ListItem Value="D" Text="D - Delete"></asp:ListItem>
</asp:DropDownList>
Based on option selected by user, I send the selected option for search in my database and retrieve records which has the selected value in the related field. My Sql usp looks like this:
ALTER PROCEDURE [dbo].[uspGetContainerSummaryRecordsForSearch] (
@fkJobID varchar(8),
@csmTaxStatus varchar(3)
)
AS
BEGIN
SET TRANSACTION ISOLATION LEVEL SNAPSHOT
SET NOCOUNT ON;
SELECT fkJobID,
csmContainerID,
csmDisplayContainerID,
csmTaxStatus
FROM ContainerSummaryRecord
where fkJobID = @fkJobID
AND ( @csmTaxStatus IS NULL
OR csmTaxStatus = @csmTaxStatus )
END
Now my question, When user selects option with Value=”” and Text=”” – Not closed”, I do not get the desired result. This is because value= “” is actually stored as null in DB.
In query i am comparing input parameter in where clause like this @csmTaxStatus IS NULL
because if user has not selected any option meaning Text=”–Select–” Value=”-1″, then the filter is not applied and all the results get returned (and this is the desired behavior for this option). But this is clashing with the Value=”” which is stored as null in DB. Kindly help.
change where condition as
just make use of
isnull()to resolve issue easily which replace null with blank as below