MS SQL 2008 syntax

I have 3 tables customer a  (with key custnum, company, address,state, zip...), contact  b (contnum, firstname, lastname, ) and cust_contact  c (cross reference whit custnum, contnum)
my task is to export data to another product using excel file in the forma for each cross reference record I have

b.contnum, b.firstname, b.lastname, a.custnum, a.company, a.address, a.zip , a.state

I am looking for exact syntax  with joins and where to get this data to new table in another SQL DB so I can export new table to excel.
leop1212Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
It's a simple JOIN:
SELECT	a.*, b.*
FROM	customer a 
	INNER JOIN cust_contact c ON a.custnum = c.custnum
	INNER JOIN contact b ON b.contnum = c.contnum;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leop1212Author Commented:
how do I build temp table to append select .  SELECT      a.*, b.*
FROM      customer a
      INNER JOIN cust_contact c ON a.custnum = c.custnum
      INNER JOIN contact b ON b.contnum = c.contnum;
?
ste5anSenior DeveloperCommented:
You normally don't need a materialized table. For a simple export it's often not necessary. Otherwise use the INTO clause:

SELECT	a.*, b.*
INTO OtherDB.dbo.tablename
FROM	customer a 
	INNER JOIN cust_contact c ON a.custnum = c.custnum
	INNER JOIN contact b ON b.contnum = c.contnum;

Open in new window


btw, please use the embed code buttons from the toolbar.

Untitled.png
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.