Solved

Populating a table from two other tables

Posted on 2014-12-11
3
78 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
Comment Utility
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
Comment Utility
So awesome,

Thanks.
0
 
LVL 12

Expert Comment

by:Koen Van Wielink
Comment Utility
Most welcome.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

744 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

19 Experts available now in Live!

Get 1:1 Help Now