I have the following code on two computers which are on different networks. On one (where I originally wrote it) it works fine. However, when it is moved to the production system, I get a syntax error on the word "FOR" in the cursor declaration. Both systems use Windows 10 Pro. The SQL Server Management Studio on which it was originally written is v17.8. I don't know what the other system's Management Studio version is. What might be the reason the production system chokes on this code? (Ignore the fact that this code would result in duplicate values in the fldWarrantyKey; another field is actually the key in this table.)
Code:
DECLARE @WarKey UNIQUEIDENTIFIER
DECLARE @WarNum VARCHAR(150)
DECLARE csrWarKey CURSOR [highlight #FCE94F]FOR[/highlight]
SELECT DISTINCT fldNumber
FROM dbo.tblWarranty
ORDER BY fldNumber
OPEN csrWarKey
FETCH NEXT FROM csrWarKey INTO[highlight #FCE94F][/highlight]
@WarNum
WHILE @@FETCH_STATUS = 0
BEGIN
SET @WarKey = NEWID()
UPDATE dbo.tblWarranty
SET fldWarrantyKey = @WarKey
WHERE fldNumber = @WarNum
FETCH NEXT FROM csrWarKey INTO
@WarNum
END
CLOSE csrWarKey
DEALLOCATE csrWarKey