rajh2504
rajh2504

Reputation: 1266

Query of queries not extracting data with data type mismatches

My client has two databases, one for the latlng of places and another database for every other table (why I don't know). I'm working off of coldfusion and from what I can tell I need to do a query of queries since CF doesn't allow for multiple datasources in the same cfquery tag. Now for some reason the primary key in the latlng table is a string and the other table is a double (again why I don't know). But in the query I have now I am testing I am not pulling any data. I'm still trying to understand how the QoQ works exactly but I think I have the general idea down. Thanks!

<cfquery name="get_restrauntinfo" datasource="#listings#" dbtype="odbc">
SELECT *
FROM listings_new
WHERE pub_code = 'GridR'
</cfquery>

<cfquery name="get_latlng" datasource="#latlng#" dbtype="odbc">
SELECT member_id, mlat, mlong
FROM maps
</cfquery> 

<cfquery name="join_rest" dbtype="query">
SELECT *
FROM get_latlng, get_restrauntInfo 
WHERE 'parseInt(get_restrauntInfo.cli_number)' = get_latlng.member_id
</cfquery> 

Upvotes: 0

Views: 147

Answers (3)

rajh2504
rajh2504

Reputation: 1266

So what I ended up doing was using CFLOOP while I'm making probably more queries then I have to it works! Here is the code:

<cfloop query="get_restrauntinfo">
    <cfquery name="get_latlng" datasource="#latlng#" dbtype="odbc">
        SELECT member_id, mlat, mlong
        FROM maps
        WHERE member_id = '#get_restrauntinfo.cli_number#'
    </cfquery>
    <cfset title = #get_restrauntinfo.publish_as#>
    var content = addContent(#get_restrauntinfo#);
    <cfoutput query="get_latlng">
        var #toScript(title, "title")#;
        addMarker(#get_latlng.mlat#,#get_latlng.mlong#, title, content, map);
    </cfoutput> 
</cfloop>

Upvotes: 0

CfSimplicity
CfSimplicity

Reputation: 2363

I would, and have seconded Charlie's answer, but to fix your existing code, you could try replacing

'parseInt(get_restrauntInfo.cli_number)'

with

CAST( get_restrauntInfo.cli_number AS INTEGER )

in your WHERE clause.

Upvotes: 1

charliegriefer
charliegriefer

Reputation: 3382

While CF doesn't allow multiple datasources within the came cfquery tag, you should still be able to join across databases. See: http://www.google.com/search?q=join+across+databases

Assuming that'll work for you, it seems a lot simpler than 2 separate queries and a QoQ on top of that.

Upvotes: 2

Related Questions