T-SQL Old style joins *= and =*

时光总嘲笑我的痴心妄想 提交于 2019-12-08 11:56:29

问题


We have about 150 old style queries and views that use the *= and =* type ANSI92? join. Does anybody know of a tool / method or script that could help with the conversion or do we have to just slog through all 150 of them.

Thanks

Select  PapersSent,
DateSent,
Code,
ActionDate,
ClientAction,
ClientContactRef,
PublishAppraisal,
PublishCV,
SponsorContactREF,
MeetingNotes,
InternalNotes,
Contact_AdminAction,
MeetingLocation
from    tblMeetingNotes a,
    tblPapersOptions b,
    tblContactLog c 

where   a.CREF=@CREF and 
    a.CLID=@CLID AND 
    Isnull(PapersSent,0)*=Value AND
    a.CREF*=c.CREF AND
    a.CLID*=c.Contact_ID

回答1:


This probably isn't what you were hoping to hear, but this type of tool doesn't exist. There are situations where an old style JOIN won't cleanly convert to the SQL-92 style, causing the query to give different results, or even requiring the query to be re-written.

Even if there were a tool to automatically convert the joins, you would still need to test every query to make sure that it converted how you wanted it to, creating probably just as much work as it would have been to do it by hand.

Erland Sommarskog has a good step-by-step process on how you would quickly convert the old style joins to SQL-92: http://www.sommarskog.se/Become-an-ANSI-star.doc




回答2:


Before you convert, I would definitely see about setting up some kind of testing framework so you can compare the results.

This will be easiest if all these are views, or if you can get the output into tables.

At that point you can use things like EXCEPT to ensure that all rows match.

In the past, I've code generated table comparisons using stored procs which take the tables/views and generate the comparisons. Even including numeric/percentage thresholds for amount differences where one set has had awkward rounding problems - like banker's rounding (Teradata) or IEEE floating point-based rounding (WebFocus).




回答3:


You could script the database and use search and replace to change the bulk of them and manually inspect the more difficult cases. Be sure to test all the queries thoroughly in case the output has changed, as mfredrickson pointed out.

To help with the search, although not strictly necessary if you script the database, download Redgate's SQL Search (it's free) to help you find all the instances. Even if you don't use it for this task it's handy to have.



来源:https://stackoverflow.com/questions/5315475/t-sql-old-style-joins-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!