这可能很简单,但我一直无法弄清楚。我有一段代码(类似于下面的代码),我通过选择将一堆值分配给一堆变量,它完成了这项工作,但是当我运行它时,我得到了导致我的 SSMS 崩溃的结果集在那里避免这种情况的方法......
DECLARE @Name VARCHAR(100)
DECLARE @LastName VARCHAR(100)
DECLARE @Address VARCHAR(100)
SELECT TOP 1
@Name = Name
@LastName = LastName
@Address = Address
From Person.Address
Where Name = 'Name'
Order By ID
我在循环中使用上面的代码,我正在处理大约 3-400K 行并将此变量传递给存储过程,每个前 1 个选择语句都会引发一个结果集,导致我的 SSMS 崩溃我真的不需要选择前 1 个值要显示,知道如何摆脱这个吗?....
任何帮助将非常感激。
---按照下面的要求是代码,我已经散列了一些东西,但这就是它,我正在从 Query Analayzer 运行它,因为这只是 1 次过程,所以我们不需要创建 SP。
DECLARE @retstat INT
DECLARE @Name VARCHAR(255)
DECLARE @Lang TINYINT
DECLARE @Address CHAR(10)
DECLARE @ID INT
DECLARE @BranchSeqNo INT
DECLARE @AddressCode VARCHAR(10)
DECLARE @Address1 VARCHAR(50)
DECLARE @City VARCHAR(30)
DECLARE @State VARCHAR(3)
DECLARE @PostalCode VARCHAR(15)
DECLARE @Country VARCHAR(30)
SET @ID = NULL
UPDATE RAWClaimTable Set Processed = 0 where Processed is null
UPDATE RAWClaimTable SET ErrorCode = NULL ,ErrorMessage = NULL ,Processed = 0
WHERE ErrorMessage IS NOT NULL AND CLAIMID is null
WHILE EXISTS ( SELECT *
FROM RAWClaimTable
WHERE Processed = 0 )
BEGIN
-----Initialize Default Variables
SET @Lang = 0
SET @Address = 'Import'
SET @SaveMode = 0
SET @ID = Null
SELECT TOP 1
@LossDate = LossDate ,
@ClaimDate = ClaimDate ,
@OpenDate = OpenDate ,
@Receivedate = ReceiVeDate ,
@Name = Name ,
@Address = Address ,
@Address1 = Address1 ,
@City = City ,
@State = State ,
@PostalCode = PostalCode ,
@Country = Country
FROM RAWClaimTable
WHERE Processed = 0
ORDER BY ClaimID
BEGIN TRY
EXEC @RetStat = Usp_ProcessRawData @Lang, @Address, @SaveMode, @ID OUT,
@BranchSeqNo, @OriginalBranchSeqNo, @IncidentID,
@AssignmentTypeCode, @PartnershipID, @AccountID,
END TRY
BEGIN CATCH
SELECT @RetStat = @@Error
if @@Trancount > 0 rollback tran
IF @RetStat != 0
BEGIN
update RAWClaimTable set Errormessage = ERROR_MESSAGE() where ClaiMKey = @Name
END
END CATCH
IF @ID IS NOT NULL
BEGIN
UPDATE RAWClaimTable
SET ClaimID = @ID ,
Processed = 1
WHERE ClaiMKey = @Name
END
ELSE
BEGIN
UPDATE RAWClaimTable
SET Processed = 1
WHERE ClaiMKey = @Name
END
END