Skip to main content
June 17, 2009
Answered

Check to see if variable is in recordset

  • June 17, 2009
  • 1 reply
  • 689 views

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?

This topic has been closed for replies.
Correct answer ilssac

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.

1 reply

ilssac
ilssacCorrect answer
Inspiring
June 17, 2009

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.

June 17, 2009

...and number 3 is the winner!

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