Error 3464 - Data type mismatch when using "DISTINCT" in SQL

I am needing help with queries that I am working on in MS Access 2003.  I currently have 3 groups created that share the same information, yet they have different factors for calculation.  I only want the distinct information for a report that I am working on.  When I run the query without DISTINCT, the information show up correctly, except for the fact that it shows up 3 times (one time for each group that I have created).  Once I try to SELECT DISTINCT, I receive the error message, "Data type mismatch in criteria expression." Can someone help me?  I hope this information is understandable; if not, feel free to ask.

Below is the code.

Thanks in advance.
Query that works:
 
SELECT  [WBS1]+' - '+[f0004_Desc] AS WBS, [f1000_Unit]+' - '+[f0003_Desc] AS Unit, tbl_COADesc.f0000_UM2, qry_Rpt1131U.COA1 AS COA, tbl_COADesc.f0000_SDesc AS [Desc], IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv])) AS Qty, tbl_COADesc.f0000_UM2 AS UM, qry_Rpt1131U.[SumOfMat Total Cost] AS TotMat, qry_Rpt1131U.SumOfTotLab AS TotLab, qry_Rpt1131U.[SumOfSub Cost] AS TotSub, qry_Rpt1131U.TotCost, qry_Rpt1131U.TotMhrs, qry_Rpt1131U.f0000_KeyQty, [TotMat]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMat, [TotLab]/IIf([TotMhrs]=0,1,[TotMhrs]) AS WRate, [TotSub]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitSC, ([TotMhrs])/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMhrs
FROM (((qry_Rpt1131U INNER JOIN tbl_0000 ON qry_Rpt1131U.COA1 = tbl_0000.f0000_PCOA) INNER JOIN tbl_0004 ON qry_Rpt1131U.WBS1 = tbl_0004.f0004_WBS) INNER JOIN tbl_0003 ON qry_Rpt1131U.f1000_Unit = tbl_0003.f0003_Area) INNER JOIN tbl_COADesc ON tbl_0000.f0000_PCOA = tbl_COADesc.f0000_PCOA;
 
 
 
Query that does not work:
SELECT DISTINCT [WBS1]+' - '+[f0004_Desc] AS WBS, [f1000_Unit]+' - '+[f0003_Desc] AS Unit, tbl_COADesc.f0000_UM2, qry_Rpt1131U.COA1 AS COA, tbl_COADesc.f0000_SDesc AS [Desc], IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv])) AS Qty, tbl_COADesc.f0000_UM2 AS UM, qry_Rpt1131U.[SumOfMat Total Cost] AS TotMat, qry_Rpt1131U.SumOfTotLab AS TotLab, qry_Rpt1131U.[SumOfSub Cost] AS TotSub, qry_Rpt1131U.TotCost, qry_Rpt1131U.TotMhrs, qry_Rpt1131U.f0000_KeyQty, [TotMat]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMat, [TotLab]/IIf([TotMhrs]=0,1,[TotMhrs]) AS WRate, [TotSub]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitSC, ([TotMhrs])/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMhrs
FROM (((qry_Rpt1131U INNER JOIN tbl_0000 ON qry_Rpt1131U.COA1 = tbl_0000.f0000_PCOA) INNER JOIN tbl_0004 ON qry_Rpt1131U.WBS1 = tbl_0004.f0004_WBS) INNER JOIN tbl_0003 ON qry_Rpt1131U.f1000_Unit = tbl_0003.f0003_Area) INNER JOIN tbl_COADesc ON tbl_0000.f0000_PCOA = tbl_COADesc.f0000_PCOA;

Open in new window

mosammeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Hope you have a column with Datatype Memo in your query and that's causing Issue.

Just remove that Memo column and give it a try.
Or try the workaround given below:

http://allenbrowne.com/ser-63.html
0
mosammeyAuthor Commented:
I am not using Memo as a data type.

Thanks.
0
SharathData EngineerCommented:
can you try like this?
SELECT [WBS1]+' - '+[f0004_Desc] AS WBS, [f1000_Unit]+' - '+[f0003_Desc] AS Unit, tbl_COADesc.f0000_UM2, qry_Rpt1131U.COA1 AS COA, tbl_COADesc.f0000_SDesc AS [Desc], IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv])) AS Qty, tbl_COADesc.f0000_UM2 AS UM, qry_Rpt1131U.[SumOfMat Total Cost] AS TotMat, qry_Rpt1131U.SumOfTotLab AS TotLab, qry_Rpt1131U.[SumOfSub Cost] AS TotSub, qry_Rpt1131U.TotCost, qry_Rpt1131U.TotMhrs, qry_Rpt1131U.f0000_KeyQty, [TotMat]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMat, [TotLab]/IIf([TotMhrs]=0,1,[TotMhrs]) AS WRate, [TotSub]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitSC, ([TotMhrs])/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMhrs
  FROM (((qry_Rpt1131U INNER JOIN tbl_0000 ON qry_Rpt1131U.COA1 = tbl_0000.f0000_PCOA) 
 INNER JOIN tbl_0004 ON qry_Rpt1131U.WBS1 = tbl_0004.f0004_WBS) 
 INNER JOIN tbl_0003 ON qry_Rpt1131U.f1000_Unit = tbl_0003.f0003_Area) 
 INNER JOIN tbl_COADesc ON tbl_0000.f0000_PCOA = tbl_COADesc.f0000_PCOA
 GROUP BY [WBS1],[f0004_Desc],[f1000_Unit],[f0003_Desc],tbl_COADesc.f0000_UM2,qry_Rpt1131U.COA1,tbl_COADesc.f0000_SDesc,
       IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv])), tbl_COADesc.f0000_UM2, 
       qry_Rpt1131U.[SumOfMat Total Cost],qry_Rpt1131U.SumOfTotLab, qry_Rpt1131U.[SumOfSub Cost], qry_Rpt1131U.TotCost, qry_Rpt1131U.TotMhrs, 
       qry_Rpt1131U.f0000_KeyQty, [TotMat]/IIf(nz([Qty],0)=0,1,[Qty]) , [TotLab]/IIf([TotMhrs]=0,1,[TotMhrs]), 
       [TotSub]/IIf(nz([Qty],0)=0,1,[Qty]) , ([TotMhrs])/IIf(nz([Qty],0)=0,1,[Qty]) ;

Open in new window

0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

mosammeyAuthor Commented:
Thanks Sharath_123, but I tried this earlier by adding the 'group by' and recieved the same message that I am receiving now....
"You tried to execute a query that does not include the specified expression'IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv]))'  as a part of the aggregate function."

Any other ideas.  I am new to Access programming and I have tried many things, but cannot get around the error message and it only displays with DISTINCT, which is weird.

Thanks....any other suggestions/ideas?
0
SharathData EngineerCommented:
lets try like this.
select distinct WBS,Unit,f0000_UM2,COA,[Desc],Qty,UM,TotMat,TotLab,TotSub,TotCost,TotMhrs,f0000_KeyQty,UnitMat,WRate,UnitSC,UnitMhrs
  from (
SELECT  [WBS1]+' - '+[f0004_Desc] AS WBS, [f1000_Unit]+' - '+[f0003_Desc] AS Unit, tbl_COADesc.f0000_UM2, qry_Rpt1131U.COA1 AS COA, 
        tbl_COADesc.f0000_SDesc AS [Desc], 
        IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv])) AS Qty, 
        tbl_COADesc.f0000_UM2 AS UM, qry_Rpt1131U.[SumOfMat Total Cost] AS TotMat, 
        qry_Rpt1131U.SumOfTotLab AS TotLab, 
        qry_Rpt1131U.[SumOfSub Cost] AS TotSub, 
        qry_Rpt1131U.TotCost, qry_Rpt1131U.TotMhrs, qry_Rpt1131U.f0000_KeyQty,
        [TotMat]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMat, [TotLab]/IIf([TotMhrs]=0,1,[TotMhrs]) AS WRate, 
        [TotSub]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitSC, ([TotMhrs])/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMhrs
FROM (((qry_Rpt1131U INNER JOIN tbl_0000 ON qry_Rpt1131U.COA1 = tbl_0000.f0000_PCOA) 
INNER JOIN tbl_0004 ON qry_Rpt1131U.WBS1 = tbl_0004.f0004_WBS) INNER JOIN tbl_0003 ON qry_Rpt1131U.f1000_Unit = tbl_0003.f0003_Area) 
INNER JOIN tbl_COADesc ON tbl_0000.f0000_PCOA = tbl_COADesc.f0000_PCOA ) as t1;

Open in new window

0
mosammeyAuthor Commented:
I feel like I am being a nuisance, and I really appreciate all of your help, but I am still getting the data type mismatch error.  I do not understand how they can pull from the same tables and and when I enter DISTINCT, the data type mismatch magically occurs....I just do not get it.  Still taking suggestions though.
0
SharathData EngineerCommented:
can you provide sample set for your working query?
0
mosammeyAuthor Commented:
I was trying to send the info below in a private message, but i did not see an option for that....

I am not sure I understand what you are asking....are you asking for the queries that I am working with or the results....or maybe both?
0
SharathData EngineerCommented:
you said that the first qurey (in your original question) is working fine. so just want to see the result set from that query.
0
mosammeyAuthor Commented:
I attached a copy of the results from the working code in the Excel file attached.

working code:
SELECT [WBS1]+' - '+[f0004_Desc] AS WBS, [f1000_Unit]+' - '+[f0003_Desc] AS Unit, tbl_COADesc.f0000_UM2, qry_Rpt1131U.COA1 AS COA, tbl_COADesc.f0000_SDesc AS [Desc], IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv])) AS Qty, tbl_COADesc.f0000_UM2 AS UM, qry_Rpt1131U.[SumOfMat Total Cost] AS TotMat, qry_Rpt1131U.SumOfTotLab AS TotLab, qry_Rpt1131U.[SumOfSub Cost] AS TotSub, qry_Rpt1131U.TotCost, qry_Rpt1131U.TotMhrs, qry_Rpt1131U.f0000_KeyQty, [TotMat]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMat, [TotLab]/IIf([TotMhrs]=0,1,[TotMhrs]) AS WRate, [TotSub]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitSC, ([TotMhrs])/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMhrs
FROM (((qry_Rpt1131U INNER JOIN tbl_0000 ON qry_Rpt1131U.COA1 = tbl_0000.f0000_PCOA) INNER JOIN tbl_0004 ON qry_Rpt1131U.WBS1 = tbl_0004.f0004_WBS) INNER JOIN tbl_0003 ON qry_Rpt1131U.f1000_Unit = tbl_0003.f0003_Area) INNER JOIN tbl_COADesc ON tbl_0000.f0000_PCOA = tbl_COADesc.f0000_PCOA;
 
non working:
SELECT distinct [WBS1]+' - '+[f0004_Desc] AS WBS, [f1000_Unit]+' - '+[f0003_Desc] AS Unit, tbl_COADesc.f0000_UM2, qry_Rpt1131U.COA1 AS COA, tbl_COADesc.f0000_SDesc AS [Desc], IIf([UM]='lot',1,IIf([f0000_UM1]=[f0000_UM2],[Quant],[Quant]*[f0000_Conv])) AS Qty, tbl_COADesc.f0000_UM2 AS UM, qry_Rpt1131U.[SumOfMat Total Cost] AS TotMat, qry_Rpt1131U.SumOfTotLab AS TotLab, qry_Rpt1131U.[SumOfSub Cost] AS TotSub, qry_Rpt1131U.TotCost, qry_Rpt1131U.TotMhrs, qry_Rpt1131U.f0000_KeyQty, [TotMat]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMat, [TotLab]/IIf([TotMhrs]=0,1,[TotMhrs]) AS WRate, [TotSub]/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitSC, ([TotMhrs])/IIf(nz([Qty],0)=0,1,[Qty]) AS UnitMhrs
FROM (((qry_Rpt1131U INNER JOIN tbl_0000 ON qry_Rpt1131U.COA1 = tbl_0000.f0000_PCOA) INNER JOIN tbl_0004 ON qry_Rpt1131U.WBS1 = tbl_0004.f0004_WBS) INNER JOIN tbl_0003 ON qry_Rpt1131U.f1000_Unit = tbl_0003.f0003_Area) INNER JOIN tbl_COADesc ON tbl_0000.f0000_PCOA = tbl_COADesc.f0000_PCOA;

Open in new window

Book1.xls
0
mosammeyAuthor Commented:
I was able to get the query working.  There was a problem with one of the queries that that I was selecting from.

Thanks for the help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.