Our databases are on SQL Server 2000.
We are migrating to SQL Server 2008 R2
.
We want to update the compatibility level to 100.
But the join operator \*=
and =\*
are no more supported with that compatibility level.
The advised solution is to update our source code and change the operators to OUTER JOINS. But we cannot afford the modification of thousand .exe
and .dll
. So we cannot update our source code; there are too many projects.
What I want to accomplish, in SQL Server 2008 R2, is the following:
- Catch the SQL statement before its execution ?
- Update the statement (i.e., replace
*=
byLEFT OUTER JOIN
) ? - Give back the modified statement to the SQL engine for execution ?
This artifice is really not advised, but it will allow us to set the compatibility level to 100 event to our program still use the old syntax.
Thanks
I posted the same question on stackoverflow before I found this specific site.
https://stackoverflow.com/questions/27320554/manipulate-sql-statement-before-execution-on-server
Best Answer
First I will just summarize my answer to this same question posted on Stack Overflow:
No, it is not possible to intercept a query request. (please see UPDATE section at the end for link to feature request)
Even if it were possible, what you are requesting ignores the complexity of what is considered valid SQL. The variations on a simple
SELECT * FROM sys.objects
increases dramatically when considering spacing, returns, [ and ], table aliases, table hints, query hints, etc. Now just add a WHERE clause and throw in some functions, etc. In the end you would break more than you would be fixing.Next, let's consider the meaning of this statement from the question:
While "afford" can be expressed in absolute terms, it is most often relative compared to alternatives. So when considering what can be "afforded", you need to consider the following:
How much of the current code base is actually affected? Do all of the thousands of files contain outer joins? Or is the real scope of work a bit smaller than "everything"?
If you can make use of Compatibility Level 80, is that being viewed as:
Because, if it is "Ok, we are done" then you are still in trouble.
I completely understand that it is a lot of work and the preference is to not do it if it's not necessary. But in all likelihood it is actually necessary. So your best bet is to develop a plan of attack regarding:
What has changed (besides removal of
*=
,=*
, and*=*
syntax) since SQL Server 2000:A final (and minor) point to consider:
What do you gain if you get what you are asking for (i.e. being able to use SQL Server 2008 R2 with one or more databases set to Compatibility Level 80):
But, you are still stuck on SQL Server 2008 R2. We are weeks away from 2015 and there could be another version of SQL Server in a year or two. That leaves you in a similar position to the current one of being on a rather old/obsolete version. The implications of that are:
Hence, what is in your company's best interest is to:
UPDATE
I submitted a Microsoft Feedback Suggestion for this ability: Intercept query batch from client to rewrite it or cancel it.