我收到错误“消息8114,级别16,状态5,过程sp_DRPL_MassChangeClient,行0错误将数据类型varchar转换为int。”

时间:2013-07-23 15:16:59

标签: sql sql-server int converter varchar

我已检查了所有相关表格,并且我已正确声明所有变量。

下面的代码调用一个非常基本的存储过程,如果需要可以提供(我不知道如何在这里正确添加)

DECLARE @DebtorsDebtID AS uniqueidentifier
    DECLARE @OldClient AS varchar(15)
    DECLARE @ClientID AS varchar(15)
    DECLARE @UserName AS varchar(20)
    DECLARE @Rows AS int
    DECLARE @Count AS int
    DECLARE @ID AS int
    DECLARE @DebtID AS int
    SET @UserName = 'rhys.bartley'
    SET @OldClient = 'TMTEST'
    SET @ClientID = 'ECCOMMERCIAL'

    SELECT tblDebt.PK_DebtID INTO #tmp
    FROM tblDebt 
    WHERE tblDebt.PK_DebtID = 233101

    SELECT @Rows = @@ROWCOUNT, @Count = 0

    WHILE (@Count < @Rows)
    BEGIN
        SELECT TOP 1 @ID = PK_DebtID FROM #tmp
        SELECT @DebtorsDebtID = PK_DebtorsDebtID FROM tblDebtorsDebt where FK_DebtID = @ID

        EXEC sp_DRPL_MassChangeClient @DebtorsDebtID,@OldClient,@ClientID,@UserName,@DebtID

        DELETE #tmp WHERE PK_DebtID = @ID
            SELECT @Count = @Count + 1
    END

sp_DRPL_MassChangeClient

USE [BailiffDB]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp_DRPL_MassChangeClient]
  @DebtorsDebtID AS uniqueidentifier,
  @DebtID AS int,  
  @OldClient AS varchar(15),
  @ClientID AS varchar(15),
  @UserName AS varchar(20)


AS
BEGIN

  SET NOCOUNT ON;
  DECLARE @BatchNo int
  SET @BatchNo = 2457


  UPDATE tblArrangement SET FK_ClientID = @ClientID WHERE FK_DebtorsDebtID = @DebtorsDebtID
  UPDATE tblDebt SET FK_ClientID = @ClientID WHERE PK_DebtID = @DebtID
  UPDATE tblDebtorsDebt SET FK_ClientID = @ClientID WHERE PK_DebtorsDebtID = @DebtorsDebtID
  UPDATE tblLetterActivity SET FK_ClientID = @ClientID WHERE FK_DebtID = @DebtID
  UPDATE tblTransactions SET FK_ClientID = @ClientID WHERE FK_DebtID = @DebtID
  UPDATE tblTransactionsDistributed SET FK_ClientID = @ClientID WHERE FK_DebtID = @DebtID
  UPDATE tblTransactionsDistributed_Cancelled SET FK_ClientID = @ClientID WHERE FK_DebtID = @DebtID
  UPDATE tblTransactions_Cancelled SET FK_ClientID = @ClientID WHERE FK_DebtID = @DebtID
  UPDATE tblDebtLoad SET FK_ClientID = @ClientID WHERE PK_DebtID = @DebtID
  UPDATE tblBatchNo SET FK_ClientID = @ClientID WHERE PK_BatchNo = @BatchNo

END

1 个答案:

答案 0 :(得分:1)

这就是你的传递

EXEC sp_DRPL_MassChangeClient @DebtorsDebtID,@OldClient,@ClientID,@UserName,@DebtID

第二个@variable是@OldClient,它被声明为varchar into

  @DebtorsDebtID AS uniqueidentifier,
  @DebtID AS int, 

第二个变量是声明为INT的@DebtID,因此引发了错误