2 Replies Latest reply on Jun 17, 2009 11:55 AM by Blue Chrome

    Check to see if variable is in recordset

    Blue Chrome Level 1

      I have a queryparam recordset in my page (let's call it rs_authorized), and I have a form-submitted value (let's call it form.county).  I want to do a <cfif> statement based on whether or not the variable is in the recordset.

       

      I have tried...

      <cfif #form.county# EQ <rs_authorized.county_name#>

      but it only recognizes if it's the first value of the recordset.

       

      I tried...

      <cfif ListFind(#rs_authorized.county_name#,#form.county#)>

      but again, it only recognizes if it's the first value of the recordset.

       

      I tried...

      <cfif #form.county# IN (#rs_authorized.county_name#)>

      but I get an error saying it doesn't recognize the word 'IN'.

       

      Any ideas?

        • 1. Re: Check to see if variable is in recordset
          ilssac Level 5

          Depending on what exactly you are trying to do here you probably need to do one or more of the following:

           

          1) Use a fully qualified record set reference of queryName.column.row:

          I.E.

          #rs_quthorized.county_name[2]#

           

          2) Loop over the recordset to search all the rows.  <cfoutput query="..."> or <cfloop query="..."> constructs make this rather easy to do, but nothing is preventing you from using any looping mechinism you care to use.

           

          3)Use the valueList(queryName.column) function to turn all the date from one column in the record set into a list.  This combined with either a listFind() or listContains() function will allow you to quickly search for a single value.

          • 2. Re: Check to see if variable is in recordset
            Blue Chrome Level 1

            ...and number 3 is the winner!

             

            Thanks, I was not familiar with the valueList() function, but it worked perfectly.  You ROCK.