I have a stored procedure as shown below; when I pass NULL for Gkol I want it to be changed to the minimum possible amount (that exists in the table), but it does not happen – why is that?
ALTER PROCEDURE sp_vUnitsUnitTejariGetFilteredUnitDetail
(@UnitFB BIT,
@UnitWithCooking BIT,
@MMofidFrom FLOAT = NULL,
@MMofidTo FLOAT = NULL,
@GKolFrom FLOAT = NULL,
@GKolTo FLOAT = NULL)
AS
BEGIN
DECLARE @MMofidCalculative BIT
DECLARE @GKolCalculative BIT
IF (@MMofidFrom IS NULL)
SELECT @MMofidFrom = MIN(MMofid)
FROM vw_PSA_UnitsUnitTejari
IF (@MMofidTo IS NULL)
SELECT @MMofidTo = MAX(MMofid)
FROM vw_PSA_UnitsUnitTejari
IF (@GKolFrom IS NULL)
SELECT @GKolFrom = MIN(GKol)
FROM vw_PSA_UnitsUnitTejari
IF (@GKolTo IS NOT NULL)
SELECT @GKolTo = MAX(GKol)
FROM vw_PSA_UnitsUnitTejari
SELECT *
FROM vw_PSA_UnitsUnitTejari
WHERE UnitTypeID = 1
AND UnitStateID = 1
AND UnitFB = ISNULL(@UnitFB, UnitFB)
AND UnitWithCooking = ISNULL(@UnitWithCooking, UnitWithCooking)
AND MMofid BETWEEN @MMofidFrom AND @MMofidTo
AND GKol BETWEEN @GKolFrom AND @GKolTo
END
I figured out why it was not working, the problem was in the last if block
I removed NOT and everything went well, thanks everyone