• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Search a string for a specific value

Explorer ,
Aug 08, 2007 Aug 08, 2007

Copy link to clipboard

Copied

I've tried a hundred things and have not got this to work. A million thanks to anyone who can help!

I have a string that consists of numbers such as 3,4,8,9,10

So I want to setup a select query to pull a value from the database if that value is located inside the string

FYI -The string is stored in a session variable....in coldfusion of course

Here is what mine looks like


<cfquery datasource="blah" >
SELECT sitenum
FROM websites
WHERE #session.rank.keep# LIKE %#webup.sitenum#%
</cfquery>

so the where in data from would be: Where 3,4,5,2,9 LIKE %4% Thanks!
TOPICS
Advanced techniques

Views

269

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 08, 2007 Aug 08, 2007

Copy link to clipboard

Copied

> LIKE %#webup.sitenum#%
Edit - I'm assuming that's a typo and that "siteNum" is a column in your table and not a variable

If the "siteNum" column type is numeric, don't use LIKE. Try an IN (...) clause instead

--- should use cfqueryparam here
WHERE sitenum IN ( #session.rank.keep#)

Which would translate to

WHERE sitenum IN (3,4,8,9,10)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 08, 2007 Aug 08, 2007

Copy link to clipboard

Copied

Bingo, thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2007 Aug 08, 2007

Copy link to clipboard

Copied

Not quite. If this list of numbers is coming from a series of check boxes or something, add something to deal with the possibility that none of them get checked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 09, 2007 Aug 09, 2007

Copy link to clipboard

Copied

LATEST
Yes, if you're not doing it already you need to add validation to handle an empty or non-existent list of values. Without it your query will throw an error

-- causes error
WHERE sitenum IN ( )

... and consider using cfqueryparam with the "list" attribute


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation