Solved

SQL Coldfusion question

Posted on 2004-10-17
5
159 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
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

756 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