Possible to do a multiple row update with multiple where conditions?

Hi,

I am hoping someone could enlighten me if what I am hoping to accomplish was possible or provide me a suggestion to my task.

I am trying to update a few rows in a table where the same column has values of 'X', 'Y', and 'Z'.

For example,

UPDATE houses_tbl
SET nShow = 1
WHERE houses_id=3 AND houses_id=5 and houses_id=7;

I have a form with a number of house pictures, and each house picture has a check box. The user checks the boxes of the houses they want displayed, and presses the submit form button. Upon form submission, the query would update the field 'nShow' = 1 for the houses that should be displayed...

Thanks guys!
CFbubuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
Sure, but you have to use the OR operator, not AND. Otherwise, the where condition will never be true, because a single house id cannot have 3 different values at the same time.

That said, instead of writing a bunch of OR conditions it's simpler to use IN (...). Just pass in your checkbox field that contains the list of id's. Obviously validate that the list is not empty first.


...

WHERE  houses_id IN (
<cfqueryparam value="#form.listOfIDs#" cfsqltype="cf_sql_integer" list="true">
)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CFbubuAuthor Commented:
Thanks for your super quick reply!

I managed to follow your logic and get the multiple update working. However, the original suggestion did not work and I had to add the string as seen below to get it to work. The only issue now is that I cannot seem to incorporate the <cfqueryparam> inside to make it work.

WHERE  houses_id IN
(#ListQualify(form.listOfIDs,"'")#)

How would I include the <cfqueryparam> to the solution above? Thanks again!
0
_agx_Commented:
Hm... it should work exactly as is, assuming it's a list of numbers like in your example.  Just be sure you added list="true".  Also, if it's a string column, just change the cfsqltype:

<!--- Don't use listQualify w/cfqueryparam. It's not needed and will cause it to fail --->
WHERE  houses_id IN (
<cfqueryparam value="#form.listOfIDs#" cfsqltype="cf_sql_varchar" list="true">
)

Did you get an error - if so what was it?
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

CFbubuAuthor Commented:
aww shucks.....I didn't notice the 'list=true' in the <cfqueryparam>...:P. Let me add it in when I am back at the computer and check it out.

Guess it's a Friday and my old eyes and not as sharp anymore... :(

Thanks for pointing that out _agx_!
0
_agx_Commented:
Lol, not like I haven't made that mistake. How else would I know to suggest it ;-)
0
CFbubuAuthor Commented:
Thank you my friend. Thank you.

You were right on the money. When I included the list=true, it worked without a hitch :)

Have a great weekend!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.