I would like to create a query that will join two tables and have the differences into columns instead of new rows.
I have a table with a companies ID and their address. In the other table i have the companies ID along with a contacts name.
Here is some sample data I made up to help get my point across.
Declare @CompanyAddress Table (companyID int, CompanyAddress char(30), CompanyState char(2))
insert into @CompanyAddress values(1, '11 14th Ave', 'NY')
insert into @CompanyAddress values(2, '228 108 street', 'NY')
Declare @CompanyContact Table (companyID int, CompanyContact char (30))
insert into @CompanyContact values(1, 'John Smith')
insert into @CompanyContact values(1, 'Amanda Adams')
insert into @CompanyContact values(1, 'Kyle Anderson')
insert into @CompanyContact values(2, 'Stan Queen')
insert into @CompanyContact values(2, 'Tim Joy')
i need the output to be similar to this, however the column title can be anything:
CompanyID CompanyAddress CompanyState CompanyContact CompanyContact CompanyContact
1 11 14th Ave NY John Smith Amanda Adams Kyle Anderson
2 228 108 street NY Stan Queen Tim Joy Null
I researched some before posting. I know a pivot table would be able to do this, but ive never used a pivot table so if you could guide me to a good tutorial or tell me how it works Ill'd greatly appreciate it.