Solved

Query SQL in compatibiliy level 80 error

Posted on 2016-09-02
3
49 Views
Last Modified: 2016-09-02
Good afternoon,

I need to execute the query below to find out the use of a table, but the base is on this basis compatibility level is 80, the error.

Does anyone know how I can adapt this script to not introduce error?

Msg 102, Level 15, State 1, Line 9
Incorrect syntax near ')'.

Queries that I need to run are attached

Thank you
query1.txt
query2.txt
0
Comment
Question by:Alex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 41782257
The solution is, you can use DB_ID(), but not directly inside a call as parameter. See for example here: http://www.sqlservercentral.com/Forums/Topic992205-391-1.aspx

If you depend on compatibility levels, because the database moved recently and you don't want to risc a compatibility issue, fix this as soon as possible, testing all your sql code to see whether the database really needs this limitation. You never do yourself a favor in keeping anything in some compatibility level, as it hinders you using new things, you don't improve.

Bye, Olaf.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 41782318
Query 1, as below.  Do similar thing for query 2.

DECLARE @db_id smallint
SET @db_id = DB_ID()

SELECT o.name AS [Table_Name], x.name AS [Index_Name],
       i.partition_number AS [Partition],
       i.index_id AS [Index_ID], x.type_desc AS [Index_Type],
       i.leaf_update_count * 100.0 /
           (i.range_scan_count + i.leaf_insert_count
            + i.leaf_delete_count + i.leaf_update_count
            + i.leaf_page_merge_count + i.singleton_lookup_count
           ) AS [Percent_Update]
FROM sys.dm_db_index_operational_stats (@db_id, NULL, NULL, NULL) i
JOIN sys.objects o ON o.object_id = i.object_id
JOIN sys.indexes x ON x.object_id = i.object_id AND x.index_id = i.index_id
WHERE (i.range_scan_count + i.leaf_insert_count
       + i.leaf_delete_count + leaf_update_count
       + i.leaf_page_merge_count + i.singleton_lookup_count) != 0
AND objectproperty(i.object_id,'IsUserTable') = 1
ORDER BY [Percent_Update] ASC
0
 

Author Closing Comment

by:Alex
ID: 41782401
thank you
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question