Solved

Populating a table from two other tables

Posted on 2014-12-11
3
79 Views
Last Modified: 2014-12-11
I need to populate a table named "TargetTable". The data to populate the table
will come from two different tables. One named Table1 and another named Table2 .
I need to tage the FUAD_ITS_CLERK_ID data from Table1 and the PSUS_USER_NUM
value from Table2 and put it into the target table. I am just lost when it comes to
figuring out the query for this. I know how to join the two tables, but not how to get
the end result of populating TargetTable. Can someone help me?


Table1 -- Spreadsheet
PSUS_USER_ID     FUAD_ITS_CLERK_ID    

s611581          CRAB                
c611689               LEXY                
y657888          MUNC                


Table2 -- SMT_ADMN_PSUS_PR_STE_USERS
PSUS_USER_NUM    PSUS_USER_ID
1                s611581
2                c611689
3                y657888


TargetTable -- Currently no data
PSUS_USER_NUM   FUAD_ITS_CLERK_ID





TargetTable -- After a query is run to populate TargetTable
PSUS_USER_NUM    FUAD_ITS_CLERK_ID
1                CRAB
2                LEXY
3                MUNC
0
Comment
Question by:brgdotnet
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Koen Van Wielink earned 500 total points
ID: 40495377
Assuming that you're already able to get the data out of the spreadsheet and into your SQL database, this query should do it.

insert into yourTargetTable
select		b.PSUS_USER_NUM
		,	a.FUAD_ITS_CLERK_ID
from	yourTable1 a
		inner join yourTable2 b
			on a.PSUS_USER_ID = b.PSUS_USER_ID
			
select *
from	yourTargetTable

Open in new window

0
 
LVL 2

Author Comment

by:brgdotnet
ID: 40495516
So awesome,

Thanks.
0
 
LVL 12

Expert Comment

by:Koen Van Wielink
ID: 40495519
Most welcome.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now