Solved

Query SQL in compatibiliy level 80 error

Posted on 2016-09-02
3
24 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
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:
ScottPletcher 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now