Solved

Need help with SQL IN clause regarding a multiple selection box

Posted on 2007-04-02
13
176 Views
Last Modified: 2013-12-24
Hey All,

    In the middle of an SQL query i have the following line:  

    WHERE location IN ('#form.categories#')    where the form.categories is the list returned from a multiple selection list box.  This query is not behaving properly because that last term gets evaluated as, for instance, the following:           Where location in ('Long Island, New York')   Where what i really need is the following:    Where location in ('Long Island', 'New York')         So you see, the quotes are not in the right place for proper functionality.  Can anyone tell me what I am doing wrong or how to fix it?  thank you.  
0
Comment
Question by:andrewaiello
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18839813
you have to put the quotes in your form.categories.
it would eventually be better to use a stored procedure for that, so it makes such complexity transparent to the (coldfusion) code
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 18839833
Thanks for replying so fast.  

     The listbox is being populated from a query so i don't know how to put the quotes in without generating the error.  The code for the box is as follows where catText would be like New York:  

              <cfselect name="categories"
                  query="getCat"
                  value="catText"
                  display="catText"
                  required="No"
                  multiple="Yes"
            
                  size=4></cfselect>
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 18839842
(reading up on coldfusion stored procedures btw ;)
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 18839906
it's due to the way cfselect passes the data


since cf is parsed before sql, a quick way might be to simply

 WHERE location IN ('#replace(form.categories, ",", "','", "all"#')

which basically transforms this


('Long Island, New York')
by replacing  the , with ','

so you get

('Long Island', 'New York') (provided i got all my "'''''s in the right place)


btw...cf doesn't -have- stored procedures...it just uses sp's from your dbms



0
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 50 total points
ID: 18839912
err...i did miss a )

sb

WHERE location IN ('#replace(form.categories, ",", "','", "all")#')
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 18839917
hmmm, pretty slick!  I'll give that a try.  Thanks for your info on stored procedures btw.  Take care.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Expert Comment

by:cyrk
ID: 18841096
You should also be able to use #QuotedValueList(FORM.Categories)#
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 75 total points
ID: 18842584
It's ok guys - I'm here now ...

cyrk - QuotedValueList is for a query column output only!!!

I believe what you're looking for is #ListQualify(FORM.Categories,"'")#
This accomplishes the same as Sid's replace statement, but I feel is slicker.
If the list(FORM.Categories) is "New York,Claire City,Melbourne"
then #ListQualify(FORM.Categories,"'")# would be 'New York','Claire City','Melbourne'
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 18842953
oh dg...yer all about the slick ;)

where ya been...working or something??

of course this illustrates what's good and also what's bad about cf there's many ways to do a thing...but it can be confusing to know which one to choose...
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 18842964
btw dg...i'd appreciate some input here..

http://www.experts-exchange.com/Database/MySQL/Q_22479194.html (it's not really a mysql q...stupid zone cross post thing goes where ever)
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 18843158
Wow you guys, thanks alot; it works now.  I used DG's method (sorry sid! ;) )   Btw, where do you guys go to look for these types of functions that don't seem to be in the standard docs.  Thanks
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 18843362
andrew ...
I'm glad it worked
most everything is in the docs.
I know listqualify is - I remember when I first found it.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 18844371
Sid - I posted in your other post ...
waiting for your reply ...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

867 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

21 Experts available now in Live!

Get 1:1 Help Now