Paul
Paul

Reputation: 1

SQL JOIN Syntax Error with Multiple Joins

SELECT
    *
FROM
    [SQL].[dbo].[Debtors] d
JOIN 
    [SQL].[dbo].[DebtorIndex] di
JOIN 
    [SQL].[dbo].[DebtorAddresses] da ON d.IDNumber = di.IDNumber
                                     AND d.AutoNumber = da.DebtorID
                                     AND da.DebtorID = '199'

I am getting this error

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'da'.

First however there is nothing there. Is there supposed to be something else there?

Second for [SQL].[dbo].[Debtors] d, I know for a fact and have triple checked that d.IDNumber & d.AutoNumber exist but I get the following error for both

"The multi-part identifier "d.IDNumber" could not be bound."

and get the same for d.AutoNumber.

Please help. Thanks in advance

Upvotes: 0

Views: 129

Answers (2)

Goose
Goose

Reputation: 546

You don’t have a join condition on di.

... di on d.something = di.anotherthing

Upvotes: 1

kjmerf
kjmerf

Reputation: 4335

Try it like this:

SELECT *
FROM [SQL].[dbo].[Debtors] d
INNER JOIN [SQL].[dbo].[DebtorIndex] di ON d.IDNumber = di.IDNumber
INNER JOIN [SQL].[dbo].[DebtorAddresses] da ON d.AutoNumber = da.DebtorID
WHERE da.DebtorID = '199'

Upvotes: 3

Related Questions