我想将一个变量初始化到 WHILE 循环中,以便我可以将该变量用于进一步的步骤。
如何为 SELECT 语句初始化 varchar 数组?我这样使用它:
DECLARE @SerialNumber AS VARCHAR
WHILE (
@SerialNumber = SELECT UnitInContainer.UnitSerialNumber
FROM UnitInContainer
WHERE ContainerCode = @Code
) IS NOT NULL
SELECT TOP 1 @CreatedUserName = UnitInStep.CreatedByUserName,
@CreatedOn = UnitInStep.CreatedOn,
@DeactivatedOn = UnitInStep.DeactivatedOn,
@UnitInContainerID = UnitInStep.UnitInContainerID,
@UnitSerialNumber = UnitInStep.UnitSerialNumber,
@ContainerCode = UnitInStep.ContainerCode,
@StepSequence = UnitInStep.StepSequence,
@RouterItemName = UnitInStep.RouterItemName,
@RouterRevisionNumber = UnitInStep.RouterRevisionNumber
FROM UnitInStep
INNER JOIN RouterStepAttribute
ON UnitInStep.RouterItemName = RouterStepAttribute.RouterItemName
AND UnitInStep.RouterRevisionNumber = RouterStepAttribute.RouterRevisionNumber
AND UnitInStep.StepSequence = RouterStepAttribute.StepSequenc
WHERE GETDATE() BETWEEN UnitInStep.CreatedOn
AND UnitInStep.DeactivatedOn RouterStepAttribute.StepTypeStepTypeValue = 'TestChamberAutoResult'
AND UnitInStep.UnitSerialNumber = @SerialNumber
END