Link to home
Start Free TrialLog in
Avatar of ttist25
ttist25

asked on

INSERT INTO SELECT JOIN THING

Hi there!

I'm working in MSSQL Server 2008 R2

I have a table "AllQuarters" with a list of distinct employee numbers [EMPLOYEE] and fields for quarterly wages for those employees like so:
---------------------------------------------------------------------------------------------------------------------------------------------
EMPLOYEE | Q1_GROSS_WAGES | Q2_GROSS_WAGES | Q3_GROSS_WAGES | Q4_GROSS_WAGES |
---------------------------------------------------------------------------------------------------------------------------------------------

I also have 4 tables (Q1 - Q4) that have the employee number [EMPLOYEE] and the gross wages [GROSS_WAGES] for the employee for that quarter.

I'm trying to join the Q1 - Q4 tables to the AllQuarters table on [EMPLOYEE] and insert the [GROSS_WAGES] from the appropriate quarter into its respective [QX_GROSS_WAGES] field in AllQuarters.

Not all employees exist in all Q1 - Q4 tables.  

I've tried INSERT INTO SELECT with a JOIN but my results end up with a bunch of NULL values.  Not sure what I'm doing wrong.  Any help will be greatly appreciated.  

TIA!
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ttist25
ttist25

ASKER

Thanks again Scott!