Skip to main content
Inspiring
October 25, 2008
Question

CF check if value in cfquery array

  • October 25, 2008
  • 3 replies
  • 1431 views
I have a <cfquery name="test" > that returns one or more "value".

I want to test <cfif X is included in test.value >

I've looked at ListContains() in LiveDocs but presume I'd have to convert structure/array (not sure which one) to a list in order to check -- or is there a StructContains() or other method that I am missing????

Newbie so this may be an easy one but thanks in advance.
    This topic has been closed for replies.

    3 replies

    Inspiring
    October 25, 2008
    Sorry - SQL expert I am not.

    You might want to try another post with a new title.

    --
    Ken Ford
    Adobe Community Expert Dreamweaver/ColdFusion
    Adobe Certified Expert - Dreamweaver CS3
    Adobe Certified Expert - ColdFusion 8
    Fordwebs, LLC
    http://www.fordwebs.com
    http://www.cfnoob.com


    "ProjectedSurplus" <webforumsuser@macromedia.com> wrote in message
    news:ge01ca$at5$1@forums.macromedia.com...
    > thanks, have that working great.
    >
    > Now (hope you don't mind) but how would I take the results of the query
    > (say
    > A, B, C) and use those to feed a new query (say SELECT * FROM table where
    > id=A,
    > then where id=B, etc).
    >
    > I realize I can probably rewrite my original select statement(s) to
    > UNION/JOIN
    > the two and then re-submit but seeing as ColdFusion already has the first
    > part
    > done I assume there is a way . . .
    >
    > . . . . I'm off to livedocs to look but if you know off-hand its much
    > appreciated.
    >

    Inspiring
    October 25, 2008
    thanks, have that working great.

    Now (hope you don't mind) but how would I take the results of the query (say A, B, C) and use those to feed a new query (say SELECT * FROM table where id=A, then where id=B, etc).

    I realize I can probably rewrite my original select statement(s) to UNION/JOIN the two and then re-submit but seeing as ColdFusion already has the first part done I assume there is a way . . .

    . . . . I'm off to livedocs to look but if you know off-hand its much appreciated.
    Inspiring
    October 26, 2008
    quote:

    Originally posted by: ProjectedSurplus
    thanks, have that working great.

    Now (hope you don't mind) but how would I take the results of the query (say A, B, C) and use those to feed a new query (say SELECT * FROM table where id=A, then where id=B, etc).

    I realize I can probably rewrite my original select statement(s) to UNION/JOIN the two and then re-submit but seeing as ColdFusion already has the first part done I assume there is a way . . .

    . . . . I'm off to livedocs to look but if you know off-hand its much appreciated.


    Take a look at the sql IN operator. The result is similar to using multiple OR conditions.

    WHERE Column IN (
    <cfqueryparam value="#yourListOfValues#" list="true" ...>
    )

    That said, a JOIN is often more appropriate and may yield better performance than an IN (...) statement. Generally the more values in your list, the slower the query. Not to mention that there are limits to the number of values allowed within an IN statement.
    Inspiring
    October 25, 2008
    Try ValueList

    http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_t-z_13.html#139169


    Description

    Inserts a delimiter between each value in an executed query. ColdFusion does
    not evaluate the arguments.

    Returns

    A delimited list of the values of each record returned from an executed
    query.

    --
    Ken Ford
    Adobe Community Expert Dreamweaver/ColdFusion
    Adobe Certified Expert - Dreamweaver CS3
    Adobe Certified Expert - ColdFusion 8
    Fordwebs, LLC
    http://www.fordwebs.com


    "ProjectedSurplus" <webforumsuser@macromedia.com> wrote in message
    news:gdtvfr$hsi$1@forums.macromedia.com...
    >I have a <cfquery name="test" > that returns one or more "value".
    >
    > I want to test <cfif X is included in test.value >
    >
    > I've looked at ListContains() in LiveDocs but presume I'd have to convert
    > structure/array (not sure which one) to a list in order to check -- or is
    > there a StructContains() or other method that I am missing????
    >
    > Newbie so this may be an easy one but thanks in advance.
    >