I get this with an 'Incorrect syntax' messasge when I run a stored procedure. if I run the 'offending' code in isolation it works fine. If I tidy the code (e.g. remove line feeds etc), the error 'moves' to a different location. HELP!
Software/Hardware used:
ASKED:
February 27, 2008 12:55 PM
UPDATED:
January 22, 2010 6:08 PM
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
“Msg 102, Level 15, State 1″ Message
I got this one when i run the re-buider index code from MS in “AdventureWorks2008.
When i run it on the others AdventureWorks databases, no problem !
see the sql code :
DECLARE tables_cursor CURSOR
FOR
SELECT s.name, t.name
FROM sys.objects AS t
JOIN sys.schemas AS s ON s.schema_id = t.schema_id
WHERE t.type = ‘U’;
OPEN tables_cursor;
DECLARE @schemaname sysname;
DECLARE @tablename sysname;
DECLARE @num int =0;
FETCH NEXT FROM tables_cursor INTO @schemaname, @tablename;
–WHILE (@num < 10)
WHILE (@@FETCH_STATUS <> -1)
BEGIN;
EXECUTE (‘ALTER INDEX ALL ON ‘ + @schemaname + ‘.’ + @tablename + ‘ REBUILD;’);
FETCH NEXT FROM tables_cursor INTO @schemaname, @tablename;
SET @num = @num + 1
END;
PRINT ‘Nbre de tables RE-INDEXEES ‘ + convert(char(03),@num);
PRINT ‘The indexes on all tables have been rebuilt.’;
CLOSE tables_cursor;
DEALLOCATE tables_cursor;