Sample Header Ad - 728x90

How to find "outer join in the where" syntax in SQL 2005 using cmptlevel 80?

0 votes
1 answer
301 views
Well last Christmas I was very happy, because we ceased support for SQL Server 2000. I could stop twisting my brain and use friendly analytical functions. (Believe me, when it comes to migrate stored procedures from SQL-Server to Oracle Analytical functions are one of your best friends). Later we discovered that we overlooked a tiny annoyance. When customers replaced there old machines by new ones, by default their compatibility level is set according to the old machine and problems are postponed until later. Which problem? Analytical functions work in SQL Server 2005 despite compatibility level 80. I'm afraid to tell that other new features like PIVOT is inhibited. Now it is good time to try to get rid of cmptlevel 80, but how? For me it is mostly scanning the procedures, views, functions and triggers for old style outer joins like '\*=' and '=*'. First let us find the defining text from the system tables. Initially it was saved in small chunks in syscomments. Hhm how to deal with the case when '*' and '=' are split onto to succeeding chunks. Next don't waste your time with Select ROUTINES from INFORMATION_SCHEMA.ROUTINES it truncates the definition to 4000 characters. Finally this is the code to query for the problematic objects: select o.name , o.type, datalength(definition) len, len(definition) len, definition from sys.sql_modules m join sysobjects o on o.id = m.object_id where (definition like '%*=%' or definition like '%=*%') But there is a further hurdle. Because default is derived from default the default width for text results is too small ( I think it is 256, but as it is the first thing I change to 8192 in SSMS, I wont bet). Any case this helps to identify the rows which need deeper examination. Perhaps sp_help displays the full definition for **all** possible cases. Perhaps it does, I don't know for sure, because I got tired of that problems created by punchcard heads. Normally I use ADO and PowerShell, but they may not be installed on the customers machine. Are there any 100% waterproof T-SQL scripts to do the job of displaying or exporting the full definition of procedures found by some condition?
Asked by bernd_k (12389 rep)
Oct 24, 2011, 06:07 PM
Last activity: Nov 2, 2011, 07:02 AM