Reputation: 2246
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?
Upvotes: 0
Views: 867
Reputation: 499002
You are passing in an empty string (''
). That is very different from NULL
.
Pass in the parameters as named parameters (without @Certified
), or test for an empty string, or pass in a NULL
.
Named parameters:
EXEC usp_ListOfVehiclesOnFuelCondition_ForSingleDealer @DealerId = '09f5245d',
@CityFeatureValue = '18',
@HwyFeatureValue = '28'
Passing a NULL
:
EXEC usp_ListOfVehiclesOnFuelCondition_ForSingleDealer '09f5245d',
NULL,
'18',
'28'
Checking for ''
:
AND (Certified = @Certified OR @Certified IS NULL OR @Certified = '')
Upvotes: 5