Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Data type mismatch

Posted on 2011-03-25
12
Medium Priority
?
195 Views
Last Modified: 2012-06-27
When I run the following query I get an error: "Data type mismatch in criteria expression"

If I remove the SMARTQtr expression the query runs ok.  What is wrong with the SMARTQtr expression?  It seems to work in other queries.  Thanks.
0
Comment
Question by:RishiSingh05
12 Comments
 
LVL 75
ID: 35217483
You will probably need to post the SQL for your query :-)

mx
0
 

Author Comment

by:RishiSingh05
ID: 35217488
Yes !! I forgot  ...

SELECT "Members" AS Id, Left(Revenue.SMARTMth,4) & " Q" & DatePart("q",DateSerial(Left(Revenue.SMARTMth,4),Mid(Revenue.SMARTMth,5),1)) AS SMARTQtr, [Cohort] & " " & [Dual/Medicaid] AS Cohort2, Sum(Revenue.[Member Count]) AS [SumOfMember Count]
FROM Revenue LEFT JOIN 6CareODSCohort ON (Revenue.[Subscriber ID] = [6CareODSCohort].MedicaidID) AND (Revenue.SMARTMth = [6CareODSCohort].Month)
GROUP BY "Members", Left(Revenue.SMARTMth,4) & " Q" & DatePart("q",DateSerial(Left(Revenue.SMARTMth,4),Mid(Revenue.SMARTMth,5),1)), [Cohort] & " " & [Dual/Medicaid];
0
 
LVL 75
ID: 35217516
I'm not seeing a Criteria expression or SMARTQtr   ?? Is there a missing WHERE clause ?

mx
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:RishiSingh05
ID: 35217576
There is no missing WHERE clause.  This is the expession for SMARTQtry:

SMARTQtr: Left(Revenue.SMARTMth,4) & " Q" & DatePart("q",DateSerial(Left(Revenue.SMARTMth,4),Mid(Revenue.SMARTMth,5),1))
0
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 35217632
Can't see anything obvious .
What is the datatype of smartmth?
0
 

Author Comment

by:RishiSingh05
ID: 35217657
text
0
 

Author Comment

by:RishiSingh05
ID: 35217702
This query works.  It does not have the expression:
SMARTQtr: Left(Revenue.SMARTMth,4) & " Q" & DatePart("q",DateSerial(Left(Revenue.SMARTMth,4),Mid(Revenue.SMARTMth,5),1))
===

SELECT "Members" AS Id, Revenue.SMARTMth, [Cohort] & " " & [Dual/Medicaid] AS Cohort2, Sum(Revenue.[Member Count]) AS [SumOfMember Count]
FROM Revenue LEFT JOIN 6CareODSCohort ON (Revenue.SMARTMth = [6CareODSCohort].Month) AND (Revenue.[Subscriber ID] = [6CareODSCohort].MedicaidID)
GROUP BY "Members", Revenue.SMARTMth, [Cohort] & " " & [Dual/Medicaid];
===
0
 

Author Comment

by:RishiSingh05
ID: 35217766
Now it works !!

SELECT "Members" AS Id, Left([Revenue].[SMARTMth],4) & " Q" & DatePart("q",DateSerial(Left([Revenue].[SMARTMth],4),Mid([Revenue].[SMARTMth],5),1)) AS SMARTQtr, [Cohort] & " " & [Dual/Medicaid] AS Cohort2, Sum(Revenue.[Member Count]) AS [SumOfMember Count]
FROM Revenue LEFT JOIN 6CareODSCohort ON (Revenue.SMARTMth = [6CareODSCohort].Month) AND (Revenue.[Subscriber ID] = [6CareODSCohort].MedicaidID)
GROUP BY "Members", Left([Revenue].[SMARTMth],4) & " Q" & DatePart("q",DateSerial(Left([Revenue].[SMARTMth],4),Mid([Revenue].[SMARTMth],5),1)), [Cohort] & " " & [Dual/Medicaid];
0
 

Author Comment

by:RishiSingh05
ID: 35217793
I have two databases.  The above SQL works in one db but not in the other ...
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 35217899
Okay, then you need to compare the datatypes in the two databases for the [Revenue] table and any other tables involved in that bit of the WHERE clause.
0
 

Author Comment

by:RishiSingh05
ID: 35217952
ok
0
 

Author Comment

by:RishiSingh05
ID: 35244065
To summarize my problem:

The following query works ok:
===
SELECT "Members" AS Id, Revenue.SMARTMth, [Cohort] & " " & [Dual/Medicaid] AS Cohort2, Sum(Revenue.[Member Count]) AS [SumOfMember Count]
FROM Revenue LEFT JOIN 6CareODSCohort ON (Revenue.SMARTMth = [6CareODSCohort].Month) AND (Revenue.[Subscriber ID] = [6CareODSCohort].MedicaidID)
GROUP BY "Members", Revenue.SMARTMth, [Cohort] & " " & [Dual/Medicaid];
===

But if I change SMARTMth to this expression: SMARTQtr: Left([Revenue.SMARTMth],4) & " Q" & DatePart("q",DateSerial(Left([Revenue.SMARTMth],4),Mid([Revenue].[SMARTMth],5),1))

so that the query becomes:
===
SELECT "Members" AS Id, Left([Revenue.SMARTMth],4) & " Q" & DatePart("q",DateSerial(Left([Revenue.SMARTMth],4),Mid([Revenue].[SMARTMth],5),1)) AS SMARTQtr, [Cohort] & " " & [Dual/Medicaid] AS Cohort2, Sum(Revenue.[Member Count]) AS [SumOfMember Count]
FROM Revenue LEFT JOIN 6CareODSCohort ON (Revenue.SMARTMth = [6CareODSCohort].Month) AND (Revenue.[Subscriber ID] = [6CareODSCohort].MedicaidID)
GROUP BY "Members", Left([Revenue.SMARTMth],4) & " Q" & DatePart("q",DateSerial(Left([Revenue.SMARTMth],4),Mid([Revenue].[SMARTMth],5),1)), [Cohort] & " " & [Dual/Medicaid];
===

I get an error message:  "Data type mismatch in criteria expression"
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question