Joe*_*tov 3 sql sql-server stored-procedures cursor query-optimization
以前存储的proc已经写了一段时间,现在需要修改.
无法联系原始开发人员,我看了一下.对我来说,这个过程似乎过于复杂.难道不能通过简单的UPDATE完成吗?任何人都可以在这里证明使用CURSOR吗?
ALTER PROCEDURE [settle_Stage1]
@settleBatch int
AS
DECLARE @refDate datetime;
DECLARE @dd int;
DECLARE @uid int;
DECLARE trans_cursor CURSOR FOR
SELECT uid, refDate FROM tblTransactions WHERE (settle IS NULL ) AND (state IN ( 21, 31, 98, 99 ))
OPEN trans_cursor
FETCH FROM trans_cursor INTO @uid, @refDate
WHILE @@FETCH_STATUS = 0
BEGIN
SET @dd = DATEDIFF( day, @refDate, getDate())
IF ( @dd >= '1' )
BEGIN
UPDATE tblTransactions
SET settle = @settleBatch WHERE uid = @uid
END
FETCH FROM trans_cursor INTO @uid, @refDate
END
CLOSE trans_cursor
DEALLOCATE trans_cursor
Run Code Online (Sandbox Code Playgroud)