我是存储过程的新手,我创建了这个游标,它将在每晚午夜运行,如果它没有停止,则翻转最后一天的记录。执行时我每次都会出错。我不确定是什么原因造成的。任何帮助将非常感激。
消息 102,级别 15,状态 1,过程 nt_rollover_charge,第 38 行“nt_cursor”附近的语法不正确。
CREATE PROCEDURE nt_rollover_charge
AS
BEGIN
SET NOCOUNT ON;
DECLARE @id VARCHAR(20);
DECLARE nt_cursor CURSOR FOR
SELECT DISTINCT log_id
FROM log_book
WHERE test_id = '3'
AND nt_dc_status = 'FALSE'
AND nt_current_date = 'TRUE';
OPEN nt_cursor
FETCH NEXT FROM nt_cursor INTO @id
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE log_book
SET nt_current_date = 'False'
WHERE log_id = @id
INSERT INTO log_book
(mrn,
fin,
ref_dr,
tech,
equip_id,
hookup_id,
indication,
abnormality,
location_id,
test_id,
charged,
start_date,
nt_rollover_date,
nt_dc_status,
nt_current_date)
(SELECT mrn,
fin,
ref_dr,
tech,
equip_id,
hookup_id,
indication,
abnormality,
location_id,
test_id,
NULL,
start_date,
getdate(),
'FALSE',
'TRUE'
FROM log_book
WHERE @id = log_id)
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM nt_cursor INTO @id
END
CLOSE nt_cursor
DEALLOCATE nt_cursor
END