Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 RE One Table With Two Outer Joins

Author  Topic 

derrellgore
Starting Member

6 Posts

Posted - 2012-02-18 : 10:17:48
Can anyone tell me how to accomplish this?

ACCOUNTINFO
ACCOUNT# SALESMANNUM NETTERMS
111111 10 110
222222 Null 130
333333 30 Null

Salesman
SNUM NAME
10 Jim
20 Dan
30 Steve

NETINFO
NTERMS NETDAYS
110 10
130 30

Result
111111 10 Jim 110 10
222222 Null Null 130 30
333333 20 Dan Null Null

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-02-18 : 12:43:59
[code]SELECT
a.[Account#],
a.SALESMANNUM,
b.[Name],
a.NETTERMS,
c.NETDAYS
FROM
AccountInfo a
LEFT JOIN Salesman b ON a.SALESMANNUM = b.SNUM
LEFT JOIN NETINFO c ON c.NTERMS = a.NETTERMS;[/code]Now that I am looking at it carefully, this query may not do what you want - not clear to me the logic used for the third row in the output. The query I posted would associate Steve with Account# 333333
Go to Top of Page
   

- Advertisement -