問題のすべてのテーブルをチェックし、すべての変数を正しく宣言しました。
以下のコードは、必要に応じて提供できる非常に基本的なストアド プロシージャを呼び出します (ここに適切に追加する方法がわかりません)。
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