经典ASP +存储过程抛出错误

时间:2017-11-20 14:10:06

标签: sql-server asp-classic

我在这里有一个非常简单的存储过程调用:

sql = "exec P_KB_GET_GK_UEBERSICHT '" & request("status") & "','" & request("jahr") & "','" & request("gkcl_vnr") & "','" & request("gkcl_name") & "','" & session("sgi") & "','" &_
            request("gk_nr") & "','" & request("gk_name") & "','" & request("gueltjahr") & "'"

这会产生如下结果:

exec P_KB_GET_GK_UEBERSICHT '','','','','D2335548','','','2017'

当我在SQL Server Management Studio中运行此命令时,我得到的输出与预期的一样。

然而,在我的ASP文件中,我收到一个错误,我显然只能用德语提供,因为我无法调整输出语言(由于缺少权限):

  

COM ERROR NR:-2147217913(0x80040E07)

     

Fehler beim Konvertieren des varchar-Werts'多样化'in den int-Datentyp

这基本上转换为:将varchar值“多样化”转换为int时出错。这是我完全陷入困境的地方。我不知道这是从哪里来的。

对于尽可能提供的情况,请参阅存储过程:

ALTER PROCEDURE [dbo].[P_KB_GET_GK_UEBERSICHT]
    @status TINYINT, 
    @jahr INT, 
    @cl_vnr BIGINT, 
    @cl_name NVARCHAR(50), 
    @sgi NVARCHAR(20), 
    @gknr NVARCHAR(4), 
    @gkname VARCHAR(50), 
    @gueltjahr INT
AS

if @cl_vnr IS NULL set @cl_vnr = 0
if @status = NULL set @status = 0
if @jahr IS NULL set @jahr = 0
if @gueltjahr IS NULL set @gueltjahr = 0
if @gknr = '' set @gknr = '0'
if @gknr IS NULL set @gknr = '0'

if @gueltjahr = 0
    select distinct CL_ID, CD_CLVID, CD_VERSION, CL_NAME, CD_JAHR, ST_NAME as CD_STATUS,
    case isNULL(CD_AKTIV,0) when 0 then 'Nein' when 1 then 'Ja' end as CD_AKTIV,
    CD_STATUS as CD_STATUS_ID, CD_VON, CD_BIS 
from dbo.V_KB_CLUSTER d
inner join dbo.V_KB_CLUSTER_GK k on d.CD_CLVID = k.KD_CLVID
left join dbo.T_KB_GK_STATUS on CD_STATUS = ST_ID
where   d.CL_ART = 'GK'
        and CD_STATUS = case when @status = 0 then CD_STATUS else @status end
        and CD_JAHR = case when @jahr = 0 then CD_JAHR else @jahr end
        and CD_CLVID = case when @cl_vnr = 0 then CD_CLVID else @cl_vnr end
        and CL_NAME like '%' + @cl_name + '%'
        and k.KD_NR = case when @gknr = '0' then k.KD_NR else @gknr end
        and k.GK_KUNDE like '%' + @gkname + '%'
order by CL_ID, CD_JAHR DESC, CD_VERSION DESC
else
    select distinct CL_ID, CD_CLVID, CD_VERSION, CL_NAME, CD_JAHR, ST_NAME as CD_STATUS,
    case isNULL(CD_AKTIV,0) when 0 then 'Nein' when 1 then 'Ja' end as CD_AKTIV,
    CD_STATUS as CD_STATUS_ID, CD_VON, CD_BIS 
from dbo.V_KB_CLUSTER d
inner join dbo.V_KB_CLUSTER_GK k on d.CD_CLVID = k.KD_CLVID
left join dbo.T_KB_GK_STATUS on CD_STATUS = ST_ID
where   d.CL_ART = 'GK'
        and CD_STATUS = case when @status = 0 then CD_STATUS else @status end
        and CD_JAHR = case when @jahr = 0 then CD_JAHR else @jahr end
        and CD_CLVID = case when @cl_vnr = 0 then CD_CLVID else @cl_vnr end
        and CL_NAME like '%' + @cl_name + '%'
        and k.KD_NR = case when @gknr = '0' then k.KD_NR else @gknr end
        and k.GK_KUNDE like '%' + @gkname + '%'
        and @gueltjahr between year(CD_VON) and isNULL(year(CD_BIS),@gueltjahr)
order by CL_ID, CD_JAHR DESC, CD_VERSION DESC 

我有数百个其他存储过程,这些不会导致此问题。也没有名为diverse的列。

有点解决

所以我发现,我必须在我的定义中使用'0'代替0

if @jahr IS NULL set @jahr = '0' 

我不明白为什么会这样。它被明确标记为INT,INT是参数(例如2017),字段定义也是INT。有人能解释一下这是什么吗?

0 个答案:

没有答案