【问题标题】:RAISERROR raises substitution parameter errorRAISERROR 引发替换参数错误
【发布时间】:2013-10-10 12:43:24
【问题描述】:

以下 T-Sql 代码:

DECLARE @usu VARCHAR(10);
SET @usu = 'TOM';
PRINT @usu;
RAISERROR ('Name of USU is %i ',14,2,@usu);

返回以下错误:

Msg 2786, Level 16, State 1, Line 4
替换的数据类型 参数 1 与格式的预期类型不匹配 规范。

有谁知道我怎样才能摆脱这个错误?

【问题讨论】:

  • 我会停止做错误消息所暗示的事情。
  • 选择严重性 14 有什么特别的原因吗?通常用于insufficient permissions
  • 请更新相当讽刺的标题,RAISEERROR当然会引发错误;)

标签: sql sql-server tsql sql-server-2005


【解决方案1】:

是的,将格式更改为Name of USU is %s%i 表示@usu 的值是有符号整数。所有格式类型显然都是documented on MSDN

【讨论】:

    【解决方案2】:

    尝试改变它:

    RAISERROR ('Name of USU is %i ',14,2,@usu); 
    

    进入那个

    RAISERROR ('Name of USU is %s ',14,2,@usu); 
    

    因为@usu 是 varchar(10) 而 %i 表示有符号整数

    【讨论】:

      【解决方案3】:

      试试

      DECLARE @usu VARCHAR(10);
      SET @usu = 'TOM'; 
      PRINT @usu; 
      --modify this line  RAISERROR ('Name of USU is %i',14,2,@usu);
      RAISERROR ('Name of USU is %s',14,2,@usu);
      

      http://msdn.microsoft.com/en-us/library/ms178592.aspx

      【讨论】:

      • 感谢您的提示。我只见树木不见森林。 -> 这么简单;-)
      • 嗨@TomStevens,如果这是答案,请将其标记为解决方案。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      相关资源
      最近更新 更多