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)
 One Table with two outer joins

Author  Topic 

derrellgore
Starting Member

6 Posts

Posted - 2012-02-17 : 21:19:35
Here is what I am trying to accomplish. With just one of the LEFT JOINs I get one line per record. With both left joins I get multiple lines for each record so I know I am not doing something right. Can anyone help with this?

EXAMPLE:

SELECT Account#, SalesmanNum, SALEMAN.Name, Netterms, NETINFO.Netdays

FROM ACCOUNTINFO

LEFT JOIN SALESMAN on ACCOUNTINFO.SalesmanNum = SALESMAN.SNUM

LEFT JOIN NETINFO on ACCOUNTINFO.Netterms = NETINFO.Nterms

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-17 : 21:36:27
maybe a join condition between SALESMAN and NETINFO ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

derrellgore
Starting Member

6 Posts

Posted - 2012-02-17 : 21:49:18
No connection between SALESMAN and NETINFO
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-17 : 21:54:47
then what is the relationship between ACCOUNTINFO and NETINFO ?

is it 1 to 1 ?



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

derrellgore
Starting Member

6 Posts

Posted - 2012-02-17 : 22:05:47
For each record I am wanting to add two fields SALESMANNAME and NETDAYS.

ACCOUNTINFO joins SALESMAN to get SALESMAN.NAME
ACCOUNTINFO joins NETINFO to get NETINFO.NETDAYS.

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-18 : 07:09:56
please show us some sample data from each of the table and the expected result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

derrellgore
Starting Member

6 Posts

Posted - 2012-02-18 : 10:13:55
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
Go to Top of Page
   

- Advertisement -