SQLTeam.com | Weblogs | Forums

Help with this problem, urgent! Thanks


#1

Finance Company 277 Distributor A(US) Dealer 1
Finance Company 277 Distributor A(US) Dealer 2
Finance Company 277 Distributor B(US) Dealer 3
Finance Company 277 Distributor C(US) Dealer 4

Finance Company 278 Distributor D(CAN) Dealer 3
Finance Company 278 Distributor D(CAN) Dealer aaa
Finance Company 278 Distributor D(CAN) Dealer bbb
Finance Company 278 Distributor E(CAN) Dealer 2

What I need to know is if any dealers that are assigned to US entity 277 have open loans to distributors in Canadian entity 278. So if you pull a open loan report for Dealers in Finance company 277 – then we should only see distributors in that listing that are assigned to 277.


#2

you need to at least explain the data or tell us the column name for the sample data. We have no idea what is US entity 277, or what is consider open loans. Not really sure how to help you.


#3

To add to @khtan, can you provide the DDL for the table (what does the create look like)?
Are you learning T-SQL? If not what have you tried?


#4

SELECT tn.*
FROM table_name tn
WHERE
[Finance Company] = '277' AND
Distributor = 'USA' /?/ AND
NOT EXISTS(
SELECT 1
FROM table_name tn2
WHERE tn2.Dealer = tn.Dealer AND tn2.Distributor = 'CAN' /?/)