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;
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;