Skip to main content
Known Participant
May 5, 2010
Answered

problem with a query inner-join

  • May 5, 2010
  • 2 replies
  • 792 views

Hello;

I'm trying to innerjoin these 2 tables in my query for a page that will allow you to add / edit records. Right now, it's telling me I have a data mismatch. I don't see where I went wrong. Can someone help me out?


This is my code:

<cfparam name="url.CategoryID" type="integer" default="0">
<cfparam name="subID" type="integer" default="#url.CategoryID#">
<cfparam name="subName" default="">
<cfparam name="CategoryID" default="">
<cfparam name="Name" default="">

<cfif url.CategoryID GT 0>
<cfquery name="categRec" dataSource="#APPLICATION.dataSource#">
SELECT merchSubCat.subName, merchSubCat.subID, Categories.CategoryID, Categories.Name
FROM merchSubCat
INNER JOIN Categories
    ON merchSubCat.CategoryID = Categories.CategoryID
WHERE merchSubCat.subID = <cfqueryparam value="#url.CategoryID#" cfsqltype="cf_sql_integer">
</cfquery>

<!--- if the record was found, store the values --->
<cfif categRec.RecordCount EQ 1>
<cfset CategoryID = categRec.subID>
<cfset subName = categRec.subName>
<cfset CategoryID = categRec.CategoryID>
<cfset Name = categRec.Name>
</cfif>
</cfif>

this is my error:

Error Executing Database Query.

[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Type mismatch in expression.
The error occurred in C:\Websites\187914kg3\admin\cms\merchant\merchSub-edit.cfm: line 16
14 : INNER JOIN Categories
15 :     ON merchSubCat.CategoryID = Categories.CategoryID
16 : WHERE merchSubCat.subID = <cfqueryparam value="#url.CategoryID#" cfsqltype="cf_sql_integer">
17 : </cfquery>
18 : 

I don't see what I did wrong, can another pair of eyes see where I missed something?

Thank you

This topic has been closed for replies.
Correct answer Ken Ford

I think you just want to use the URL.CategoryID parameter:

<cfselect enabled="No" name="CategoryID" size="1" class="smallText" multiple="no" query="catList" value="CategoryID" display="cat_name" queryPosition="below" selected="#URL.CategoryID #">
<option value="">--Select a Category--</option>
</cfselect>

Ken Ford

2 replies

Participating Frequently
May 5, 2010

You probably have the wrong type of CFSQLTYPE here:

WHERE merchSubCat.subID = <cfqueryparam value="#url.CategoryID#" cfsqltype="cf_sql_integer">

Try cf_sql_numeric instead:

WHERE merchSubCat.subID = <cfqueryparam value="#url.CategoryID#" cfsqltype="cf_sql_numeric">

Ken Ford

Inspiring
May 5, 2010

FROM merchSubCat

INNER JOIN Categories

    ON merchSubCat.CategoryID = Categories.CategoryID

WHERE merchSubCat.subID = <cfqueryparam

value="#url.CategoryID#" cfsqltype="cf_sql_integer">

What are the data types of the columns:

merchSubCat.CategoryID

Categories.CategoryID

merchSubCat.subID

Known Participant
May 5, 2010

it's an access database..

merchSubCat.CategoryID - text

Categories.CategoryID - auto number

merchSubCat.subID - auto number

should I make merchSubCat.CategoryID a number field?