Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL syntax for LEFT OUTER JOIN in SQL Server 2012

We're having an issue with SQL Server 2012 due to the lack of support for the *= (LEFT OUTER JOIN) operator.

Can anyone tell me what is the correct syntax for SQL Server 2012 for the following SQL that worked correctly on SQL Server 2008?

SELECT 
    t7410.name, t7408.type, t7410.length, 
    t7410.status, t7410.prec, t7410.scale, 
    t7409.type 
FROM 
    dbo.syscolumns t7410, dbo.systypes t7408, 
    dbo.sysobjects t7409, dbo.sysusers t7411, 
    master.dbo.syslogins t7412 
WHERE 
    t7410.id = t7409.id 
    AND t7411.uid = t7409.uid 
    AND t7409.name = 'GENERAL'
    AND t7409.type IN ('U', 'S', 'V') 
    AND t7410.usertype *= t7408.usertype 
    AND t7412.sid = t7411.sid 
    AND t7412.name = user_name() 
ORDER BY 
    t7410.colid ASC
like image 371
Steve Graber Avatar asked Nov 20 '12 21:11

Steve Graber


People also ask

What is the syntax for a left outer join?

The syntax for the LEFT OUTER JOIN in MySQL is: SELECT columns FROM table1 LEFT [OUTER] JOIN table2 ON table1.

What is left outer join in SQL Server?

Another type of join is called a SQL Server LEFT OUTER JOIN. This type of join returns all rows from the LEFT-hand table specified in the ON condition and only those rows from the other table where the joined fields are equal (join condition is met).

What does (+) mean in SQL join?

The plus sign is Oracle syntax for an outer join. There isn't a minus operator for joins. An outer join means return all rows from one table. Also return the rows from the outer joined where there's a match on the join key. If there's no matching row, return null.


1 Answers

Why not write this using ANSI JOIN syntax:

SELECT t7410.name, t7408.type, t7410.length, 
    t7410.status, t7410.prec, t7410.scale, 
    t7409.type 
FROM dbo.syscolumns t7410
INNER JOIN dbo.sysobjects t7409
    ON t7410.id = t7409.id
INNER JOIN dbo.sysusers t7411
    ON t7411.uid = t7409.uid 
INNER JOIN master.dbo.syslogins t7412 
    ON t7412.sid = t7411.sid 
LEFT JOIN dbo.systypes t7408
    ON t7410.usertype = t7408.usertype 
WHERE t7409.name = 'GENERAL'
    AND t7409.type IN ('U', 'S', 'V') 
    AND t7412.name = user_name() 
ORDER BY t7410.colid ASC
like image 50
Taryn Avatar answered Oct 30 '22 14:10

Taryn