Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Merging 3 tables

Author  Topic 

10Dawg
Starting Member

46 Posts

Posted - 2011-12-14 : 14:54:09
I have 3 tables (.xls) I want to merge in sql.
1-I need to create a database with tbl01. tbl01 has a ContactID and AccountID among many other fields.
2- I need to merge tbl02 with tbl01 with the common field of AccountID.
3- I need to merge tbl03 with tbl01 with the common field of ContactID.

BTW, there is a many to one ratio, Contact>Account. How do I sort this out?

10Dawg

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-15 : 00:02:41
two methods

1. export all excel sheets to sql staging tables using export/import wizard and then use join between them
2. use OPENROWSET to pull data from different sheets and do the join

i prefer method 1 as join involving OPENROWSET can be slow especially when amount of data is large

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

Go to Top of Page

10Dawg
Starting Member

46 Posts

Posted - 2011-12-16 : 10:58:24
Sorry but I'm a newie to programming. How do I use sql staging tables?

Also I was told today that all the comments per each contact need to be in the same (cell) divided by a delimeter (let's say a colon : ). Is there a link or book that has this situation as a project that I can follow along and adapt to my situation?

10Dawg
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-16 : 11:01:36
use export/import wizard and dump excel data to sql table created for temporary purpose called staging table

for the second part use this

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

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

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-12-16 : 11:01:52
you need to post the table structures and sample data and what the expect output is suppose to look like (based on the sample data)



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -