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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with T-SQL Statment

Author  Topic 

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2010-03-30 : 10:04:14
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..

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-30 : 10:08:33
Maybe it is only the newline between dm_db_index_physical_stats and the following (


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -