Solved

Populating a table from two other tables

Posted on 2014-12-11
3
80 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 13

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 13

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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 the fundamental information of how to create a table.

809 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