Help needed with appending an union query in Access

Dankniseley

New Member
Joined
Mar 23, 2003
Messages
33
I am trying to write a SQL query that randomly pulls data thru an ODBC connection. I have basically 3 different data pulls but have combined them into one query using UNION ALL.

I want to take the results from this query and INSERT INTO my LV table.

Is there a way to do this. I keep getting a FROM Clause ERROR when I run the following Query. This query Runs with out the INSERT INTO [LV] line.

Any help would greatly be appreciated.

Dan

*************************************************************************************************************************
INSERT INTO [LV]

Select * FROM (

SELECT TOP 100
dbo_NetworkMapping_2003.Carrier_Code,
dbo_NetworkMapping_2003.invc_nbr,
dbo_NetworkMapping_2003.BOL,
dbo_NetworkMapping_2003.Shipper_Ref_No,
dbo_NetworkMapping_2003.Origin_Port_code,
dbo_NetworkMapping_2003.Dest_Port_Code,
dbo_NetworkMapping_2003.Ship_Date,
dbo_NetworkMapping_2003.Paid_Date,
dbo_NetworkMapping_2003.Shipper_Name,
dbo_NetworkMapping_2003.Consignee_Name,
dbo_NetworkMapping_2003.invc_mtch_type_cd,
dbo_NetworkMapping_2003.frght_term_cd,
dbo_NetworkMapping_2003.invc_tot_usd_amt,
dbo_NetworkMapping_2003.Paid_Quarter,
dbo_NetworkMapping_2003.FP_ID,
Rnd([FP_ID]) AS Random_Value
FROM dbo_NetworkMapping_2003
WHERE dbo_NetworkMapping_2003.Shipper_Ref_No Not Like "Ref*"
And
dbo_NetworkMapping_2003.invc_tot_usd_amt between 0.00 And 3000.00
And
dbo_NetworkMapping_2003.Paid_Quarter="2003-Q3"
ORDER BY Rnd([FP_ID])

)XXX

Union All

Select * FROM (

SELECT TOP 100
dbo_NetworkMapping_2003.Carrier_Code,
dbo_NetworkMapping_2003.invc_nbr,
dbo_NetworkMapping_2003.BOL,
dbo_NetworkMapping_2003.Shipper_Ref_No,
dbo_NetworkMapping_2003.Origin_Port_code,
dbo_NetworkMapping_2003.Dest_Port_Code,
dbo_NetworkMapping_2003.Ship_Date,
dbo_NetworkMapping_2003.Paid_Date,
dbo_NetworkMapping_2003.Shipper_Name,
dbo_NetworkMapping_2003.Consignee_Name,
dbo_NetworkMapping_2003.invc_mtch_type_cd,
dbo_NetworkMapping_2003.frght_term_cd,
dbo_NetworkMapping_2003.invc_tot_usd_amt,
dbo_NetworkMapping_2003.Paid_Quarter,
dbo_NetworkMapping_2003.FP_ID,
Rnd([FP_ID]) AS Random_Value
FROM dbo_NetworkMapping_2003
WHERE dbo_NetworkMapping_2003.Shipper_Ref_No Not Like "Ref*"
And
dbo_NetworkMapping_2003.invc_tot_usd_amt between 3000.00 And 6000.00
And
dbo_NetworkMapping_2003.Paid_Quarter="2003-Q3"
ORDER BY Rnd([FP_ID])


)YYY

UNION ALL Select * FROM (
SELECT TOP 100
dbo_NetworkMapping_2003.Carrier_Code,
dbo_NetworkMapping_2003.invc_nbr,
dbo_NetworkMapping_2003.BOL,
dbo_NetworkMapping_2003.Shipper_Ref_No,
dbo_NetworkMapping_2003.Origin_Port_code,
dbo_NetworkMapping_2003.Dest_Port_Code,
dbo_NetworkMapping_2003.Ship_Date,
dbo_NetworkMapping_2003.Paid_Date,
dbo_NetworkMapping_2003.Shipper_Name,
dbo_NetworkMapping_2003.Consignee_Name,
dbo_NetworkMapping_2003.invc_mtch_type_cd,
dbo_NetworkMapping_2003.frght_term_cd,
dbo_NetworkMapping_2003.invc_tot_usd_amt,
dbo_NetworkMapping_2003.Paid_Quarter,
dbo_NetworkMapping_2003.FP_ID,
Rnd([FP_ID]) AS Random_Value
FROM dbo_NetworkMapping_2003
WHERE dbo_NetworkMapping_2003.Shipper_Ref_No not like "*Ref*"
And
dbo_NetworkMapping_2003.invc_tot_usd_amt between 6000.00 And 9999.99
And
dbo_NetworkMapping_2003.Paid_Quarter="2003-Q3"
ORDER BY Rnd([FP_ID])
)lll;
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,221,581
Messages
6,160,630
Members
451,661
Latest member
hamdan17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top