0
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

2
  • 1
    What is the difference between AutoNumber and IDNumber? It sounds like they're both IDENTITY or primary-key attributes, in which case one is redundant. Also avoid using the term "Autonumber" as it doesn't apply to SQL Server. Commented Oct 28, 2017 at 5:44
  • That is a field that is in my data and is used as it is unique Commented Oct 28, 2017 at 14:36

2 Answers 2

3

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'
Sign up to request clarification or add additional context in comments.

2 Comments

I did that but nothing shows up. When you type '199' something should show up when i do the searches manually however get no results when I do it with this sql statement
I'd have to look at the data to answer why
1

You don’t have a join condition on di.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.