I have this stored procedure
ALTER PROCEDURE [dbo].[usp_mySP]
-- Add the parameters for the stored procedure here
-- For inventory table check.
@DealerID VARCHAR(50),
@Certified VARCHAR(50) = NULL,
-- For fuel value.
@CityFeatureValue VARCHAR(50),
@HwyFeatureValue VARCHAR(50)
AS
BEGIN
BEGIN
SELECT InventoryID,
VIN
FROM Inventory
WHERE DealerID = @DealerID
AND Deleted = 'False'
AND (IsPending = '0' OR IsPending IS NULL)
--AND (Certified = @Certified OR @Certified IS NULL)
AND VIN IN
(
SELECT VIN
FROM FuelPerformance
WHERE (
FeatureTitle = 'Fuel Economy (City)'
AND FeatureValue = @CityFeatureValue
)
OR
(
FeatureTitle = 'Fuel Economy (Hwy)'
AND FeatureValue = @HwyFeatureValue
)
GROUP BY VIN
HAVING COUNT(VIN) > 1
)
END
END
I am calling it like :
EXEC usp_ListOfVehiclesOnFuelCondition_ForSingleDealer
'09f5245d' , '', '18', '28'
When I am commenting the line
AND (Certified = @Certified OR @Certified IS NULL)
it is giving the result, but when this line is there the result is blank.
Any suggestion where I am doing wrong?
You are passing in an empty string (
''). That is very different fromNULL.Pass in the parameters as named parameters (without
@Certified), or test for an empty string, or pass in aNULL.Named parameters:
Passing a
NULL:Checking for
'':