Solved

SQL Coldfusion question

Posted on 2004-10-17
5
161 Views
Last Modified: 2013-12-24
Well, I met another problem I cant see a solution to.

In my database a column contains a list of IDs as a string which is generated by checkboxes. I need a right solution to query the database.

Say, one record can contain just number 1 and another 1,3,4,9.
In my search form I also use checkboxes and got a list.
Say a search string is 1,4,9

I need a query which will look at the list from search form, compares value with the recorded string and if it matches the record is queried.
Say in my case I must get both records, because first one contains "1" and second one contains "1", "4" and "9".


0
Comment
Question by:Wasistdas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 17

Accepted Solution

by:
Tacobell777 earned 125 total points
ID: 12334409
If you want to query strings in the database you are going to have to do some very complicated and resource hoggin stuff - what you need to do is add another table and insert each value from the string into that table and link it to the record where the string was stored with.

Trust me, its the worst thing you can do store a list of values in a database and then search through it.
0
 
LVL 7

Assisted Solution

by:black0ps
black0ps earned 125 total points
ID: 12334416
That might be pretty difficult to query it in that way. I don't know a ton about MSSQL, but I don't think you will be able to loop through lists as strings.

You could try something like this:

<cfquery>
Select * From MyColumn
Where
<cfloop from="1" to="#ListLen(Form.Search)#" index="i">
<cfif i NEQ 1>OR </cfif>
MyColumn Like '#ListGetAt(Form.Search,i)#'
</cfloop>
</cfquery>

Instead of looping through the values in the column, you loop through the numbers in form field. A potential problem could be in you have a row with the values 1,3,10,101. If you searched on 1, you could pull up 3 different records.

You might also want to consider creating another table in the database specifically for the search. Perhaps someone else might have some more input on this topic.

-- Ian
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
Suggested Courses

623 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