Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting with Union

Status
Not open for further replies.

rickpill

Programmer
Feb 28, 2002
108
US
I am new to SQL and have been trying for sometime now to get this query to work (provided to me by another member as noted). I'm trying to select data from two table containing promotional data and inserting unique account rows selected into a third table:


BUYER:
AccountNumber
SaleNumber
Price
... other Buyer related data
CountryCode
State
ZipPostCode
City


SELLER:
AccountNumber
SaleNumber
Price
... other Seller related data
CountryCode
State
ZipPostCode
City

SELECTIONS:
CampaignID
AccountNumber
CountryCode
State
ZipPostCode
City

**********************************************************
Here's the query by Terry L. Broadbent - DBA (TLBROADBENT)

INSERT Selections
(AccountNumber, CountryCode,
State, ZipPostCode, City)
SELECT
AccountNumber, CountryCode,
State, ZipPostCode, City
(SELECT
AccountNumber, CountryCode,
State, ZipPostCode, City
FROM Buyer
WHERE (SaleNumber = 'nyc00001')
AND (Price > 1000)

UNION

SELECT
AccountNumber, CountryCode,
State, ZipPostCode, City
FROM Seller
WHERE (SaleNumber = 'nyc00001')
AND (Price > 1000)) As Qry

***********************************************************
The first problem I had with this query was a syntax problem, I added "INTO", reran the query and got a "unsupported" error message.
***********************************************************

Thanks,

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top