我创建了一个存储过程来将所有项目从 IDx 移动到 IDz,并且它必须记录它移动的每一行的一些数据。该过程将行从 ID< 移动到 IDz 没有任何问题。但是当它必须记录信息时,它只记录移动的最后一行。我究竟做错了什么?
这是我的代码:
USE [TrackIT_Test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[MoveCustIDAndAlias]
-- Add the parameters for the stored procedure here
@SourceAdrID int,
@TargetAdrID int,
@Username varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @custID varchar(50)
set @custID = ''
declare @alias varchar(50)
set @alias = ''
-- Insert statements for procedure here
Select @custID = (CustID), @alias = (Alias) from dbo.Alias where AdrID = @SourceAdrID;
Insert into dbo.AliasMoveLog (CustID, Alias, Username) VALUES (@custID, @alias, @Username);
UPDATE dbo.Alias SET AdrID = @TargetAdrID WHERE AdrID = @SourceAdrID;
任何人都可以帮忙吗?