Solved

How do you check to see if query results contain a string?

Posted on 2008-10-02
1
250 Views
Last Modified: 2012-05-05
I have two queries; the first one simply returns a list (of, say, all letters of the alphabet) and the second  returns a varying number of letters. What I want to do is print out the results of the first query highlighting the ones that are contained in the second query. I'm guessing it would be done something like the following:

<cfloop query="qAlphabet">
   <cfif [qSelectLetters contains qAlphabet.letter]><b></cfif>
   #qAlphabet.letter#
   <cfif [qSelectLetters contains qAlphabet.letter]></b><cfif>
   <br/>
</cfloop>

But I'm unsure of how to phrase the part in the brackets. I've done it by setting a string (looping through query 2, to give something like "a,c,g,w" and seeing if that string contains qAlphabet.letter, but it seems like that would be excessively huge if the queries were involving blocks of text, not just letters.
0
Comment
Question by:SiobhanElara
1 Comment
 
LVL 15

Accepted Solution

by:
danrosenthal earned 250 total points
ID: 22629267
The syntax for your example would be something along the lines of:

<cfif LISTFIND(valuelist(qAlphabet.letter),qSelectLetters)>

But, you are correct in that it wouldn't be wise to use that solution for larger resultsets.

I would recommend doing the comparing at the SQL level. Either in the original query using a LEFT JOIN, or by using a query of queries.

Rough example of how you would use a LEFT JOIN to acheive the desired result:

SELECT
   a.value
   , CASE WHEN b.joinID IS NOT NULL THEN 1 ELSE 0 END as isrecordfound
FROM allrecordtable a
LEFT JOIN myvaluetable b
ON a.joinID = b.joinID

And your CFIF inside the output loop would be simply:

<cfif isrecordfound eq 1>


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question