SQL Server存储过程需要参数,该参数未提供

时间:2013-05-14 21:16:05

标签: sql-server tsql

CREATE   PROCEDURE dbo.SP_GUILD_CHAR_CREATE 
    @i_guild_code           VARCHAR(10)     ,   --길드코드
    @i_character_name       VARCHAR(40)     ,   --캐릭터명
    @i_peerage_code         VARBINARY(1)    ,   --작위코드
    @o_sp_rtn               INT     OUTPUT  ,   --실행결과
             @2mx_user_no           varchar(50)

AS
DECLARE 
    @v_max_char_cnt         int,        --한길드당 최대 길드원 수
    @v_row_cnt              int
BEGIN   
    SET NOCOUNT ON
    SET @o_sp_rtn = -1
    SET @v_max_char_cnt = 50

    --입력값 검증
    IF  @i_guild_code IS NULL       OR 
        @i_character_name IS NULL   OR
        @i_peerage_code IS NULL     BEGIN
        SET NOCOUNT OFF
        SET @o_sp_rtn = -1
        RETURN
    END

    --길드중복가입 검사.
    IF EXISTS(  SELECT  1
                FROM    dbo.GUILD_CHAR_INFO WITH(NOLOCK)
                WHERE   character_name = @i_character_name )
    BEGIN
        SET NOCOUNT OFF
        SET @o_sp_rtn = -2
        RETURN
    END

    --한길드당 최대 길드원 수 검증
    SELECT  @v_row_cnt = count(*)
    FROM    dbo.GUILD_CHAR_INFO WITH(NOLOCK)
    WHERE   guild_code = @i_guild_code 
    IF @@Error <> 0 BEGIN
        SET NOCOUNT OFF
        SET @o_sp_rtn = -3
        RETURN
    END

    IF @v_max_char_cnt <= @v_row_cnt BEGIN
        SET NOCOUNT OFF
        SET @o_sp_rtn = -4
        RETURN
    END

    --길드원 등록

SET @2mx_user_no = (SELECT user_no FROM user_character 
WHERE character_name = @i_character_name)

    BEGIN TRAN
    INSERT INTO dbo.GUILD_CHAR_INFO
          (
            guild_code          ,
            character_name      ,
            peerage_code        ,
            ipt_time            ,
            upt_time                           ,
                                        user_no             
          )
    VALUES(
            @i_guild_code           ,
                                        @2mx_user_no        ,
            @i_character_name               ,
            ISNULL(CAST(@i_peerage_code AS smallint), 9)        ,
            getdate()                       ,
            getdate()
          )
    IF @@Error <> 0 
    BEGIN
        ROLLBACK TRAN
        SET NOCOUNT OFF
        SET @o_sp_rtn = -9
        RETURN 
    END

COMMIT TRAN
SET NOCOUNT OFF
SET @o_sp_rtn = 0
END
GO

存储过程出错:

  

SQL存储过程需要参数,该参数未提供。

我收到了这个错误,我无法真正理解它的错误。请尽量详细。

我不知道哪个参数没有提供,我应该如何修复

1 个答案:

答案 0 :(得分:1)

您的存储过程需要五个参数:

  1. @i_guild_code VARCHAR(10)
  2. @i_character_name VARCHAR(40)
  3. @i_peerage_code VARBINARY(1)
  4. @o_sp_rtn INT OUTPUT
  5. @ 2mx_user_no varchar(50)
  6. 程序中没有提供默认值。您的调用代码必须在其sql命令中提供这些参数。

    如果从.NET类调用它,则应确保SqlCommand中包含所有参数。这是一个相关的问题:

    What's the best method to pass parameters to SQLCommand?

    请务必设置SqlParameter

    .Direction属性

    如果使用sql脚本直接运行它们,则需要在执行调用后显式包含参数。有关示例,请参阅MSDN Article