SQL Import Query

RavenTim
RavenTim used Ask the Experts™
on
I have a select query that I run, gathering data from two tables, using the join function (see below).  Currently, I save the results to an excel spreadsheet, then import it into the 'billing' table using the import wizard.

I'm wondering if there is a way to augment this query to include an import command so the data will append the data in the 'billing' table.  

Here's the select query:
SELECT     b.Shipped, b.track, a.Ref, a.Acct, a.Sender, a.R_name, a.R_add1, 
	a.R_add2, a.R_City, a.R_State, a.R_Zip, a.Weight, a.Weight_charge, a.xtra_desc, 
	a.xtra_amt, a.[service], a.charges, a.driver, a.sent_by, a.Inv_no, a.surcharge,
	a.dups, a.created_by, a.created_date, a.release, a.last_update, a.run_count, 
	a.shipper, a.xtra_inv_amt, a.web_attn_to, a.web_Phone, a.web_suite, 
	a.other_charge_reason, a.area_charge, a.residential_charge
FROM         KTBSMaster a
left outer join KTBSdaily b on a.companyid = b.companyid
WHERE     b.CompanyID = a.companyid

Open in new window


Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Insert into billing
SELECT     b.Shipped, b.track, a.Ref, a.Acct, a.Sender, a.R_name, a.R_add1,
      a.R_add2, a.R_City, a.R_State, a.R_Zip, a.Weight, a.Weight_charge, a.xtra_desc,
      a.xtra_amt, a.[service], a.charges, a.driver, a.sent_by, a.Inv_no, a.surcharge,
      a.dups, a.created_by, a.created_date, a.release, a.last_update, a.run_count,
      a.shipper, a.xtra_inv_amt, a.web_attn_to, a.web_Phone, a.web_suite,
      a.other_charge_reason, a.area_charge, a.residential_charge
FROM         KTBSMaster a
left outer join KTBSdaily b on a.companyid = b.companyid
WHERE     b.CompanyID = a.companyid
 
If the fields in the billing table dont match the query then you have to name the fileds eg

Insert into billing (field1, field2, field3,......)
SELECT     b.Shipped, b.track, a.Ref, a.Acct, a.Sender, a.R_name, a.R_add1,
      a.R_add2, a.R_City, a.R_State, a.R_Zip, a.Weight, a.Weight_charge, a.xtra_desc,
      a.xtra_amt, a.[service], a.charges, a.driver, a.sent_by, a.Inv_no, a.surcharge,
      a.dups, a.created_by, a.created_date, a.release, a.last_update, a.run_count,
      a.shipper, a.xtra_inv_amt, a.web_attn_to, a.web_Phone, a.web_suite,
      a.other_charge_reason, a.area_charge, a.residential_charge
FROM         KTBSMaster a
left outer join KTBSdaily b on a.companyid = b.companyid
WHERE     b.CompanyID = a.companyid


Author

Commented:
WOW!!!  THAT'S IT!  TOO EASY!

THANKS EWANGOYA

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial