Skip to content
Advertisement

SQL Query results into a already created table

I need some help getting the results from this query:

SELECT 
    a.RouteNumber, b.DPS - a.BaseDPS AS DiffDPS, 
    b.Flats - a.BaseFlats AS DiffFlats, 
    b.Parcels - a.BaseParcels AS DiffParcels 
FROM 
    Sheet1$ b
INNER JOIN 
    RouteInfo a ON b.RouteNumber = a.RouteNumber

To go into a table I have already created (Routegen). Routegen already has the columns (RouteNumber, DPS, Flats, Parcels).

I’ve tried using SELECT INTO, but apparently I’m not doing it right because I can’t get the code to run after changing it.

The main goal here is to compare then subtract data from both tables and put it into a new table. I feel like I’m close, just need a little help!

Thank you for your help guys!

Advertisement

Answer

You want insert ... select:

INSERT INTO Routegen (RouteNumber, DPS, Flats, Parcels)
SELECT a.RouteNumber, b.DPS - a.BaseDPS, b.Flats - a.BaseFlats, b.Parcels - a.BaseParcels
FROM Sheet1$ b
INNER JOIN RouteInfo a ON b.RouteNumber=a.RouteNumber
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement