I'm getting an error "Msg 8114, Level 16, State 5, Procedure sp_DRPL_MassChangeClient, Line 0 Error converting data type varchar to int."

StackOverflow https://stackoverflow.com/questions/17814262

Domanda

I've checked all the tables in question and I've declared all variables correctly.

the code below calls on a very basic stored procedure which can be provided if needed (I'm not sure how to add it in here properly)

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
È stato utile?

Soluzione

This is what your passing

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

the second @variable is @OldClient which is declared as varchar into

  @DebtorsDebtID AS uniqueidentifier,
  @DebtID AS int, 

The second variable is @DebtID declared as INT hence the error thrown

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top