5 pts.
 Msg 102, level 15, State 1, Line 102
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

Answer Wiki:
Are you running the code using Management Studio (SQL 2005) or Query Analyzer (SQL 2000)? Sometimes the "compiler" cannot ubicate the exact place where the error appears. You can create the SP in phases: each time place the "go" in a different place and see what are the parts that run successfully without returning the error, until you reach the problematic place. It would help me help you if you could post the code of the Proc. Regards, Michelle. When debugging SQL Procedures you need to remember to remove the white space above the ALTER PROCEDURE line when counting down the lines. What happens if you run the entire procedure out side of the procedure. In order words comment out the ALTER PROCEDURE line and manually set any input parameters. Then when the error comes up you can double click on it to get to the offending line(s) of code.
Last Wiki Answer Submitted:  March 2, 2008  9:34 pm  by  SQL Server and databases   165 pts.
All Answer Wiki Contributors:  SQL Server and databases   165 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,520 pts.

 

“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;

 10 pts.