?
Solved

Query SQL in compatibiliy level 80 error

Posted on 2016-09-02
3
Medium Priority
?
55 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:Support_38
[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 1000 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:Support_38
ID: 41782401
thank you
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

770 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