Skip to main content
Participating Frequently
July 30, 2010
Question

cfqueryparam causes no records to return some of the time

  • July 30, 2010
  • 3 replies
  • 1873 views

I have a query set up as

select  a.coulmn1, a.coulmn2, c.coulmn3, a.coulmn4
from general_view a, second_view c
where a.id = c.id
and a.coumn1 = <cfqueryparam value="#form.selected_from_previous_dropdown#" cfsqltype="cf_sql_varchar" maxlength="20">
and c.some_other_column= ('#query2.other_column#')

if i remove the <cfqueryparam> portion it runs fine. If i add the query param it some times does not. Is the syntax in error or does cfquery param alter input in some way that would sometimes result in 0 matches when in fact the records should match the criteria?

    This topic has been closed for replies.

    3 replies

    godfoggedAuthor
    Participating Frequently
    August 3, 2010

    I have to do more testing but i may found a solution. I changed the cfsqltype to char instead of varchar.

    Inspiring
    July 30, 2010

    The maxlength attribute looks like it might contribute to unexpected results.  When it doesn't work, does it crash or simply return something other than what you anticipated?

    godfoggedAuthor
    Participating Frequently
    August 2, 2010

    i tried it without the maxlength and got the same result.

    Inspiring
    July 30, 2010

    So you're saying that this:

    <cfquery name="q" datasource="whatever">

    select  a.coulmn1, a.coulmn2, c.coulmn3, a.coulmn4
    from general_view a, second_view c
    where a.id = c.id
    and a.coumn1 = <cfqueryparam value="#form.selected_from_previous_dropdown#" cfsqltype="cf_sql_varchar" maxlength="20">
    and c.some_other_column= ('#query2.other_column#')

    </cfquery>

    and this:

    <cfquery name="q" datasource="whatever">

    select  a.coulmn1, a.coulmn2, c.coulmn3, a.coulmn4
    from general_view a, second_view c
    where a.id = c.id
    and a.coumn1 = '#form.selected_from_previous_dropdown#'

    and c.some_other_column= ('#query2.other_column#')

    </cfquery>

    return different results?

    What is the value of #form.selected_from_previous_dropdown# ?

    --

    Adam

    PS: is that query reflective of your actual DB schema?  You spell "column" three different ways...

    godfoggedAuthor
    Participating Frequently
    August 2, 2010

    they return different results. Sometimes it works properly other times it just returns an empty data set.

    The value in the previously selected drop down is text

    Inspiring
    August 2, 2010

    The value in the previously selected drop down is text

    Sure, but what is the actual value.  An example of the value that has been selected.  The SQL doesn't care where it came from, but it might care what the actual value is...

    --

    Adam