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!

Data Type Mismatch help 1

Status
Not open for further replies.

matthej

MIS
Mar 3, 2005
8
US
I have two queries that I'm trying to union. One pulls cost of inventory and the other pulls cost of goods sold. Each query also returns manufacturer. I want to union the two queries. Here’s what I have:

SELECT [Prior Month].MFG, [Prior Month].Cost as [Cost of Goods Sold], '' as [PURCH COST]
FROM [Prior Month]
Union
SELECT Inventory.MFG, '', Inventory.[PURCH COST]
FROM Inventory

As you can see, the Prior Month table doesn’t contain the Purch Cost (cost of inventory) field and the Inventory table doesn’t contain the Cost (Cost of Goods sold) field. I want a query that returns those two fields along with Manufacturer so that I can then use a Crosstab query and do a summary by Manufacturer.

When I export each query separately into Excel, the cost fields show up as numbers. However, when I union the two queries and export the result, the numbers are exported as text. Additionally, Access won't SUM on these numbers and tells me that there's a data type mismatch. I assume that's because the union query turns the cost fields into text. In the base tables, those two fields are set up as numbers.

How do I use the union query appropriately to get the cost fields to be returned as numbers instead of text?

I’ve tried to do a search on this topic, but haven’t found anything, so I apologize in advance if it’s a repeat subject.

I appreciate any help you can provide.

Thanks, Matthej
 
The Union requires the same # of columns of the same data type in both select lists.

SELECT 1 as type, [Prior Month].MFG, [Prior Month].Cost as [Cost of Goods Sold]
FROM [Prior Month]
Union
SELECT 2 as type, Inventory.MFG, Inventory.[PURCH COST]
FROM Inventory


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top