0

我有一个如下所示的存储过程;当我通过时NULLGkol我希望将其更改为尽可能少的数量(存在于表中),但它没有发生 - 为什么会这样?

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
4

1 回答 1

0

我弄清楚为什么它不起作用,问题出在最后一个 if 块

if(@GKolTo is not null)

我删除了NOT,一切顺利,谢谢大家

于 2012-08-01T04:58:30.000 回答