SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Joins
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vergy39
Starting Member

USA
15 Posts

Posted - 12/24/2012 :  17:46:37  Show Profile  Reply with Quote
Merry Christmas everyone. I have a question regarding Joins. I have a 3 tables in a database. One that has most data and utilizes ID's that are named in other tables. For example: TableData consists of columns of ConfirmationNumber, AssociateNumber, ReasonID, ApprovedByAssociateNumber, UpdatedByAssociateNumber. I need to join the tables that identify the ReasonID, AssociateNumber, ApprovedByAssociateNumber and the UpdatedByAssociateNumber. They are identified on tables called AssociateInfo, and ReasonInfo. The reason one is easy however, the assoiateinfo one is hard because the AssociateName and UpdateByAssociateNumber are to utilize the same column from the AssociateInfo table. If I join that table twice, such as :
Use MainDatabase
Select ConfirmationNumber, a.AssociateNumber, b.NameFirst AS AssocFrstName, b.NameLast AS AssocLstName, c.ReasonName, d.ApprovedByAssociateNumber, d.NameFirst AS ApprvdByFirstname, d.NameLast AS apprvdByLastName
From TableData a
INNER JOIN tbl.AssociateInfo b ON a.AssociateNumber = b.AssociateNumber
INNER JOIN tbl.AssociateInfo c On a.ApprovedByAssociateNumber = c.AssociateNumber

Hope this helps.

Thanks
David V

Edited by - Vergy39 on 12/24/2012 17:59:26

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/25/2012 :  09:08:33  Show Profile  Reply with Quote
This looks like quite simple but your explanation seems confusing. Can you post Sample Data and Expected Output?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/26/2012 :  00:02:56  Show Profile  Reply with Quote
sounds like a self join to me which is what you're using too. So didnt understand issue you're facing. What happened when you used posted query?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Vergy39
Starting Member

USA
15 Posts

Posted - 01/23/2013 :  16:59:25  Show Profile  Reply with Quote
Well the Holidays are over and I am back trying to make this work again. I also have another situation where this will help involving a query that returns the name of an associate, their immediate supervisor, and their manager. All information is on one table, but only the names of the associates are paired with the associateID. in order to get their immediate supervisor, I have the immediate supervisors assocID which I need to match up to the name. Is there a way to send an attachment that shows the data in an excel sheet? Maybe that would help. Let me know.

Thanks
David V
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000