Whats the meaning with using Curly Braces {} in a query?

  • From another programmer, I have inherited this code:

    ...FROM
     {oj dbo.Dagbogsnote DAG  LEFT OUTER JOIN dbo.PERSONAL PER ON DAG.DAG_PERSONAL_ID=PER.PER_PERSONAL_ID LEFT OUTER JOIN dbo.Fokusomr FOK ON DAG.DAG_FOKUSOMR_ID=FOK.FOK_FOKUSOMR_ID}...

    There must be a reason for {}, but i cannot find it.

    A look in GOOGLE says something about not valid code, but not easy understandable.

    Not very important, but  I like to understand what i use.

    Best regards

    Edvard Korsbæk

  • It's an OUTER JOIN: Outer Joins.

    Why you would use that syntax now though...

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thanks for the explanation.
    I have never used 'OUTER JOIN', and really does not understand what it is.
    So, that will be the next to find out, but thats pretty much easier to find.

    Best regards

    Edvard Korsbæk

  • Edvard Korsbæk - Friday, November 2, 2018 3:25 AM

    Thanks for the explanation.
    I have never used 'OUTER JOIN', and really does not understand what it is.
    So, that will be the next to find out, but thats pretty much easier to find.

    I hate you ask, but you're saying you've never used a LEFT (OUTER) JOIN, RIGHT (OUTER) JOIN or FULL OUTER JOIN?

    Have a look at SQL Joins (W3Schools) for the basics on the type of joins in SQL. You can find the documentation on JOINs for SQL server in FROM (Transact-SQL) - JOIN hint.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thanks again!

    I found :

    LEFT (OUTER) JOIN

    Left JOIN is used pretty much by me, and it seems like OUTER can be wriiten or not.

  • Edvard Korsbæk - Friday, November 2, 2018 4:42 AM

    Thanks again!

    I found :

    LEFT (OUTER) JOIN

    Left JOIN is used pretty much by me, and it seems like OUTER can be wriiten or not.

    OUTER is a readability word. It has no effect on processing logic. Whether it gets included or not is a matter of house style – I tend to remove readability words because they do nothing except waste space. Others will disagree!

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • The link in the first response by Thom A explains that the { oj ... } syntax is an ODBC escape sequence.  Which leads me to believe that this code is in a client app that is connecting to SQL Server through an ODBC connection.  That construction is interpreted by the ODBC provider and rewritten to suit the database, if you capture the actual query with a database trace it will look different.  Maybe the original developer was obsessed with being database-agnostic and did it that way so it would work anywhere.

    But this query does not seem to be too complicated to write in standard SQL that should run anywhere without ODBC tricks.  Based on this one example, the ODBC escape sequence is not adding anything and just making future maintenance more confusing.

  • A better answer is that, in general, curly braces in a query are used for ODBC escape sequences.  Meaning the enclosed text is not standard SQL or T-SQL, it is interpreted as ODBC syntax.

    This shows use of other ODBC language features in SQL queries:
    https://docs.microsoft.com/en-us/sql/t-sql/functions/odbc-scalar-functions-transact-sql?view=sql-server-2017

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply