Solved

Query SQL in compatibiliy level 80 error

Posted on 2016-09-02
3
45 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

733 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