This SQL code is not working

SELECT tt.[Member ID],
       tt.Contact,
       tt.DOB,
       cl.[Member ID],
       cl.Contact,
       cl.DOB
  FROM (SELECT cl.[Member ID],
               cl.Contact,
               cl.DOB,
               tt.[Member ID],
               tt.Contact,
               tt.DOB
          FROM twothousandsone AS tt LEFT OUTER JOIN
               ContactList AS cl ON tt.[Member ID] = cl.[Member ID]
         WHERE cl.[Member ID] IS NULL
       ) AS nt LEFT OUTER JOIN
       dbo.ContactList cl (ON nt.Contact = cl.Contact)
 WHERE cl.Contact Is NULL
   AND cl.DOB IS NULL

Hello a team member in a different forum has helped me a lot and I owe him for helping me on this script and brought this code to this point. But still it is not working, any help? Regards GGGG

June 8th, 2013 8:32am

Whats your error message?

Free Windows Admin Tool Kit Click here and download it now
June 8th, 2013 8:37am

This is the error:

Msg 156, Level 15, State 1, Line 18
Incorrect syntax near the keyword 'ON'.

When I put this  (ON nt.Contact = cl.Contact) in Parenthesis.

When I take the parenthesis off: this is the error message:

Msg 8156, Level 16, State 1, Line 18
The column 'Member ID' was specified multiple times for 'nt'.
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "tt.Member ID" could not be bound.
Msg 4104, Level 16, State 1, Line 4
The multi-part identifier "tt.Contact" could not be bound.
Msg 4104, Level 16, State 1, Line 5
The multi-part identifier "tt.DOB" could not be bound.

I am new to SQL Server, and I have taken a course and I have picked up some of the basics and I need help to get started on it.  I need to learn it to find a job.

How do you find from Error message what the problem is?

GGGGGNNNNN

June 8th, 2013 8:53am

Try the below:

SELECT nt.M2,
       nt.C2,
       nt.D2,
       cl.[Member ID],
       cl.Contact,
       cl.DOB
  FROM (SELECT cl.[Member ID] M1,
               cl.Contact C1,
               cl.DOB D1,
               tt.[Member ID] M2,
               tt.Contact C2,
               tt.DOB D2
          FROM twothousandsone AS tt LEFT OUTER JOIN
               ContactList AS cl ON tt.[Member ID] = cl.[Member ID]
         WHERE cl.[Member ID] IS NULL
       ) AS nt LEFT OUTER JOIN
       dbo.ContactList cl (ON nt.C2 = cl.Contact)
 WHERE cl.Contact Is NULL
   AND cl.DOB IS NULL

Free Windows Admin Tool Kit Click here and download it now
June 8th, 2013 9:14am

If this is the same problem you posted in Access Developers Forum, please see my response in the Access Developers thread.

June 8th, 2013 6:29pm

Hello Latish,

Can you please tell me how you found how to alias the fields?

Regards,

GGGGGNNNNN

Free Windows Admin Tool Kit Click here and download it now
June 8th, 2013 8:58pm

Hello Latish,

Can you please tell me how you found how to alias the fields?

Regards,

GGGG

June 8th, 2013 9:33pm

Thank you for your help and I think it is clear. How can I get started on Microsoft SQL?

I have already done two courses.

Regards,

GGGGGNNNNN

Free Windows Admin Tool Kit Click here and download it now
June 8th, 2013 10:23pm

Try this book -

Microsoft SQL Server 2012 T-SQL Fundamentals by Itzik Ben-Gan

http://www.amazon.com/Itzik-Ben-Gan/e/B001IGQENW

Also, unless we practice we don't know the FUN with SQL Server programming, its my personal experience.

You can take topic from your training sessions, practice with some examples, don't hesitate to ask GOOGLE for help.

June 8th, 2013 10:49pm

I already have Beginning Microsoft SQL Server 2008 Programming/ Robert Vieira.

I think yours is better as I look at inside.

Thank you for the help.

Regards,

GGGGGNNNNN

Free Windows Admin Tool Kit Click here and download it now
June 8th, 2013 11:33pm

Sarat,

I just want to thank you for the book you introduced me, I owe you a lot. GGGGGNNNNN

January 20th, 2014 11:58pm

Hello Sarat,

I need a book in Microsoft Access that I can refer to it and it brings me a lot of queries. I need to practice placing different queries in various scenarios. Do you know of anything?

Regards,

GGGGGNNNNN

Free Windows Admin Tool Kit Click here and download it now
January 21st, 2014 12:08am

Hello Sarat,

I need a book in Microsoft Access that I can refer to it and it brings me a lot of queries. I need to practice placing different queries in various scenarios. Do you know of anything?

Regards,

GGGG

January 21st, 2014 4:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics