Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with my T-SQL Statement

Author  Topic 

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2010-03-30 : 10:30:35
Hello -

I'm in the process of using a script that will help with re-indexes. I keep getting the following errors.

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'ELSE'.

My database name is Backdrop and the table is dbo.PJTRAN and the index is pjtran0. Here is the script if someone can help me understand why I keep getting those errors.


IF EXISTS (SELECT [object_id],[index_id],[avg_fragmentation_in_percent] FROM sys.dm_db_index_physical_stats
(DB_ID(N'Backdrop'), OBJECT_ID(N'PJTRAN.PJTRAN0'), NULL, NULL , 'DETAILED')
WHERE [avg_fragmentation_in_percent] < 30)

BEGIN

ALTER INDEX ALL ON PJTRAN REORGANIZE

END
ELSE

ALTER INDEX ALL ON PJTRAN REBUILD


Thank you..

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2010-03-30 : 13:09:21

IF EXISTS (SELECT [object_id],[index_id],[avg_fragmentation_in_percent] FROM sys.dm_db_index_physical_stats
(DB_ID(N'Backdrop'), OBJECT_ID(N'PJTRAN.PJTRAN0'), NULL, NULL , 'DETAILED')
WHERE [avg_fragmentation_in_percent] < 30)

BEGIN

ALTER INDEX ALL ON PJTRAN REORGANIZE

END
ELSE

ALTER INDEX ALL ON PJTRAN REBUILD



I do not see any error from that part.

Could you post the entire script up here?

Note: the condition is likely always true?!!?
Go to Top of Page
   

- Advertisement -