Solved

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

Posted on 2008-10-02
1
237 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now