存储过程不适用于Muli参数

时间:2019-03-13 12:22:22

标签: sql sql-server stored-procedures

我的SP未返回准确结果集,请看

CREATE PROCEDURE [dbo].[SP_withMulpti_parameter] --   [dbo].[SP_withMulpti_parameter] '','2019','',''
(   @date date,
    @casenumber varchar(100),
    @AdvocateName varchar(100),
    @PartyName varchar(100))
AS
BEGIN
    SET NOCOUNT ON;


    IF ((@casenumber IS NULL
      OR @casenumber = '')
    AND (@date IS NULL
      OR @date = '')
    AND (@AdvocateName IS NULL
      OR @AdvocateName = '')
    AND @PartyName IS NOT NULL)
    BEGIN
        SELECT 1;
    END;
    ELSE IF ((@casenumber IS NULL
           OR @casenumber = '')
         AND (@date IS NULL
           OR @date = '')
         AND @AdvocateName IS NOT NULL
         AND @PartyName IS NOT NULL)
    BEGIN
        SELECT 2;
    END;
    ELSE IF ((@casenumber IS NOT NULL
           OR @casenumber <> '')
         AND (@date IS NULL
           OR @date = '')
         AND (@AdvocateName IS NOT NULL
           OR @AdvocateName <> '')
         AND (@PartyName IS NOT NULL
           OR @PartyName <> ''))
    BEGIN
        SELECT 3;
    END;
    ELSE IF (((@casenumber IS NOT NULL)
          AND (@date IS NOT NULL)
          AND (@AdvocateName IS NOT NULL
            OR @AdvocateName <> '')
          AND @PartyName IS NOT NULL))
    BEGIN
        SELECT 4;
    END;
    ELSE IF ((@casenumber IS NULL
           OR @casenumber = '')
         AND (@date IS NULL
           OR @date = '')
         AND @AdvocateName IS NOT NULL
         AND (@PartyName IS NULL
           OR @PartyName = ''))
    BEGIN
        SELECT 5;
    END;
    ELSE IF ((@casenumber IS NULL OR @casenumber = ''))
    BEGIN
        SELECT 6;
    END;
    ELSE IF (@date IS NULL OR @date = '')
    BEGIN
        SELECT 7;
    END;
    ELSE
    BEGIN
        SELECT 8;
    END;

END;

1 个答案:

答案 0 :(得分:0)

请尝试这个。

CREATE PROCEDURE [dbo].[SP_withMulpti_parameter] --   [dbo].[SP_withMulpti_parameter] '','2019','',''
(   @date date,
    @casenumber varchar(100),
    @AdvocateName varchar(100),
    @PartyName varchar(100))
AS
BEGIN
    SET NOCOUNT ON;


    IF ((ISNULL(@casenumber,'') = '')
        AND (ISNULL(@date ,'') = '')
        AND (ISNULL(@AdvocateName ,'') = '')
        AND @PartyName IS NOT NULL)
    BEGIN
        SELECT 1;
    END;
    ELSE IF ((ISNULL(@casenumber,'') = '')
        AND (ISNULL(@date ,'') = '')
         AND @AdvocateName IS NOT NULL
         AND @PartyName IS NOT NULL)
    BEGIN
        SELECT 2;
    END;
    ELSE IF ((ISNULL(@casenumber,'') <> '')
         AND (ISNULL(@date ,'') = '')
         AND (ISNULL(@AdvocateName ,'') <> '')
         AND (ISNULL(@PartyName ,'') <> ''))
    BEGIN
        SELECT 3;
    END;
    ELSE IF (((@casenumber IS NOT NULL)
          AND (@date IS NOT NULL)
          AND (ISNULL(@AdvocateName ,'') <> '')
          AND @PartyName IS NOT NULL))
    BEGIN
        SELECT 4;
    END;
    ELSE IF ((ISNULL(@casenumber,'') = '')
        AND (ISNULL(@date ,'') = '')
         AND @AdvocateName IS NOT NULL
         AND (ISNULL(@PartyName,'') = ''))
    BEGIN
        SELECT 5;
    END;
    ELSE IF (ISNULL(@casenumber,'') = '')
    BEGIN
        SELECT 6;
    END;
    ELSE IF (ISNULL(@date ,'') = '')
    BEGIN
        SELECT 7;
    END;
    ELSE
    BEGIN
        SELECT 8;
    END;

END;