Link to home
Start Free TrialLog in
Avatar of Juan Ocasio
Juan OcasioFlag for United States of America

asked on

Complex SQL statement (at least for me) to insert values into a table using other tables in my database

Hello all:

This is probably very easy, but I do not know how to accomplish the task.  I three tables.  One table is a temp table that was loaded from an excel file.  The other two tables are a header table and detail table.'

So what I have to do is load the two tables from the temp table (there was really 2 temp tables, but I've already loaded that into the header table in my database).

User generated image
I need to do something like:
INSERT INTO detailTable (Uniqueid, Address, State)
and here is where I'm not sure about the select statement.  

I have to get the h.uniqueid from headertable h inner join temptable t on h.HeaderID = t.HeaderID
and I also need to make sure all of the results in the from are only in the tempdetail

Any help would be greatly appreciated
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India 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
SOLUTION
Avatar of _agx_
_agx_
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 Juan Ocasio

ASKER

LOL  That was easy.

Thanks for your help!
You're welcome.. and thanks for posting such a clear question.  Having the table layout and expected results always makes it much easier to help  :)