The script works fine when it has 2 rows. Stop reading from 3.
This is MSSQL Server 2005. Try anyway without any result.
DECLARE @CurrentAccountLevel int DECLARE @CurrentAccountExpireDate smalldatetime SELECT @CurrentAccountLevel=Type,@CurrentAccountExpireDate=Date FROM T_VIPList IF(@CurrentAccountLevel <> 0 AND getdate() > @CurrentAccountExpireDate) BEGIN SET @CurrentAccountLevel = '0' UPDATE T_VIPList SET Type=@CurrentAccountLevel,Date=@CurrentAccountExpireDate END
There is no error message. But if I have more than 10 rows, it doesn’t affect the row that should affect.
Advertisement
Answer
Given the new information in your comment you should simplify this to an update statement. There is no need for variables, IF statements etc.
UPDATE T_VIPList SET Type = '0' where Date < getdate() and Type <> '0'