question

namcit avatar image
namcit asked

how to use join with old kind (+) in SQL server

use qlns select * from table1, table2 where table1.manv = table2.manv(+) error : Msg 102, Level 15, State 1, Line 2 Incorrect syntax near ')'. i use SQL Server 2012.i know how to use LEft outer join.But i try to use (+)
sqlserver2012
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered
That's Oracle syntax, not SQL Server. The 'old' join in SQL Server was select * from table1, table2 where table1.manv =* table2.manv or select * from table1, table2 where table1.manv *= table2.manv but that was discontinued in SQL Server 2012, and was deprecated from 2008.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Oleg avatar image Oleg commented ·
The 'old' syntax in Oracle uses the + sign to the right of the table being joined to, while in T-SQL the \* was on the "correct side" of the equal sign. It is actually great news that they finally discontinued support for the old syntax because it would occasionally cause issues since all conditions (join conditions and the after join predicates) were bunched together in the where clause so there was no guarantee that they would be executed in the correct order. For example, suppose you have a table named Employee and another table named Dependent which has 0-to-many relationship to Employee. Now, try to write a query using the old syntax to return records for those employees which don't have dependents. It would seem that this should work:
select
    e.*
    from dbo.Employee e, dbo.Dependent d
    where e.ID *= d.ID and d.ID and d.ID is null
Unfortunately, the above fails returning all employee records. This is because d.ID is null is evaluated first, before the join condition, and since none of the Dependent records has ID is null, all records are eliminated and therefore, all employee records are returned. Restating it properly with left join works as expected of course.
1 Like 1 ·
namcit avatar image
namcit answered
thank for consider
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

namcit avatar image
namcit answered
i learn that syntax from http://www.techonthenet.com/sql_server/joins.php so the website composes wrong information
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.