Incorrect syntax near '(' | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Incorrect syntax near ‘(‘

If I take the first SQL example from Reorganizing and Rebuilding Indexes and try to execute it, it fails with this error: "Msg 102, Level 15, State 1, Line 4 Incorrect syntax near ‘(‘." Here’s the SQL that fails:
USE our_db_name;
GO
SELECT a.index_id, name, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(N’Resume.Skills_tbl’),
NULL, NULL, NULL) AS a
JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id;
GO This, however, works:
select database_id, object_id, index_type_desc, avg_fragmentation_in_percent, avg_fragment_size_in_pages, avg_page_space_used_in_percent, record_count, page_count, fragment_count, avg_record_size_in_bytes
from sys.dm_db_index_physical_stats(db_id(‘our_db_name’), NULL, NULL, NULL, ‘DETAILED’); Questions:
1. What’s wrong with the first SQL from the Microsoft article?
2. What’s the use of the "N" in "OBJECT_ID(N’Resume.Skills_tbl’)"?
quote:Originally posted by bryan42
Questions:
1. What’s wrong with the first SQL from the Microsoft article?
2. What’s the use of the "N" in "OBJECT_ID(N’Resume.Skills_tbl’)"?

1.Both the queries work at my side. What version you are using?
2. Just to specify that the parameter in NVARCHAR. The parameter is SYSNAME which is NVARCHAR(124)
Roji. P. Thomas
SQL Server MVP
http://toponewithties.blogspot.com

Thanks, Roji! I’m using Microsoft SQL Server Management Studio 9.00.1399.00 so access a remotely hosted Sql Server 2005 database on Windows Server 2003.

]]>