Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Update Table Based on a JOINSQL Advent 2012 Day 10: SQL Server Maintenance »
    comments

    This month’s T-SQL Tuesday is hosted by Sebastian Meine (blog | twitter) and the topic is joins. He has a whole month worth of topics about joins: A Join A Day – Introduction.

     

     

     

     

     

    My blog post is about something weird I encountered while I was converting some old Oracle code to T-SQL (I encounter all sorts of weird stuff in Oracle code, but let’s stay on topic). Amongst all the usual cursor-madness, I stumbled upon this query:

    1. SELECT mt1.Column1, mt2.Column2
    2. FROM [dbo].[MyTable1] mt1, [dbo].[MyTable2] mt2
    3. WHERE      mt1.[JoinColumn1] (+)= mt2.[JoinColumn1]
    4.        AND mt1.[JoinColumn2] (+)= mt2.[JoinColumn2]

    The original query was much longer and more complex, but I kept only the necessary parts. I recognised the old-style of writing joins, also known as ANSI-89 joins (read more about them in Bad habits to kick : using old-style JOINs). However, I never came across the type of join designated by a (+)=. Most likely this has something to do what my lack of experience with Oracle, which I am very proud of :). SQL Server didn’t recognise the syntax so it had to be either Oracle only, or something very outdated. I asked about this on Twitter and a few people came up with compound operators which were introduced in SQL Server 2008, but luckily Mladen Prajdic (blog | twitter) vaguely remembered those could be LEFT OUTER JOINs.

    * UPDATE: Apparently this syntax coresponds with RIGHT OUTER JOIN. For more info, see Robs comment below *

    And he was right. After some Googling I found this Oracle doc page: Joins. It is described as the “Oracle join operator”. They advise not to use it, but you know, stuff like this always pops up in legacy code.

    So, if you’re converting some old Oracle code (we have to get rid of it once, don’t we?), now you know how to deal with this monstrosity.

    About the Author

    User bio imageKoen Verbeeck is a Microsoft Business Intelligence consultant at Ordina Belgium, helping clients to get insight in their data. Koen has a comprehensive knowledge of the SQL Server BI stack, with a particular love for Integration Services. He's also a speaker at various conferences.
    Social SitingsTwitterLinkedInLTD RSS Feed
    2712 views
    InstapaperVote on HN

    6 comments

    Comment from: SQLDenis [Member] Email
    SQLDenis Nice post, I must say that I rarely see *= or =* (the old style SQL Server outer joins) anymore. I did mention it in the Join post from last year's SQL Advent calendar
    12/11/12 @ 03:42
    Comment from: Koen Verbeeck [Member] Email
    Interesting, I was wondering if SQL Server had an equivalent syntax to (+)=. Good to know if I ever have to update legacy SQL Server code :)
    12/11/12 @ 04:25
    Comment from: SQLDenis [Member] Email
    SQLDenis The good thing is that SQL Server doesn't support that syntax anymore
    12/11/12 @ 04:43
    Comment from: Rob Farley [Visitor] · http://sqlblog.com/blogs/rob_farley
    Rob Farley Actually, if the (+) appeared before the = that made it a RIGHT outer join. The plus was along the lines of "plus nulls".

    So a left join would be written as:

    WHERE t1.col = t2.col (+)
    AND ...

    (equivalent to t1.col *= t2.col in T-SQL)

    And a right join would be:

    WHERE t1.col (+) = t2.col
    AND ....

    (equivalent to t1.col =* t2.col in T-SQL)

    Hope this helps,

    Rob
    12/11/12 @ 06:42
    Comment from: Koen Verbeeck [Member] Email
    Hi Rob, thanks for posting your comment. You're right.
    After re-reading the Oracle doc a few times, it makes more sense now.

    I think it's time to review some of my code :)
    12/11/12 @ 06:55
    Comment from: Valentino Vranken [Visitor] · http://blog.hoegaerden.be
    Valentino Vranken What's certainly clear from this post, comments inclusive, is that this is some really confusing syntax. Glad to see that *= is gone as well! :)
    12/12/12 @ 01:02

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)