Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] 'Case' in CB query

  • squil
  • squil
  • OFFLINE
  • Posts: 42
  • Thanks: 1
  • Karma: 0
11 years 3 months ago - 11 years 3 months ago #231442 by squil
[SOLVED] 'Case' in CB query was created by squil
What wrong in may query!?

SELECT CASE WHEN cb_towncheck='Other' THEN city ELSE cb_towncheck END CASE FROM `znaji_comprofiler` WHERE user_id ='[user_id]'
Last edit: 11 years 3 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48466
  • Thanks: 8280
  • Karma: 1443
11 years 3 months ago #231463 by krileon
Replied by krileon on topic 'Case' in CB query
Enable debug mode and maximum error reporting in Joomla global configuration. Then visit the page it's supposed to be enabled on and it'll error out if there's an error in the query. Also test within your database directly using phpmyadmin (replacing [user_id] with an ID to test) and see if it works as expected.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: squil

Please Log in or Create an account to join the conversation.

  • squil
  • squil
  • OFFLINE
  • Posts: 42
  • Thanks: 1
  • Karma: 0
11 years 3 months ago #231514 by squil
Replied by squil on topic 'Case' in CB query
That's true....
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE FROM `znaji_comprofiler` WHERE `user_id` ='266' LIMIT 0, 30' at line 1


Can you halp me!?
How can I make a query with CASE!? Example?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48466
  • Thanks: 8280
  • Karma: 1443
11 years 3 months ago #231530 by krileon
Replied by krileon on topic 'Case' in CB query
Please see the below MYSQL documentation regarding case.

CASE:
dev.mysql.com/doc/refman/5.6/en/case.html

Usage of CASE in SELECT:
dev.mysql.com/doc/refman/5.6/en/control-flow-functions.html

General SQL Tutorials:
www.w3schools.com/sql/default.asp

You're probably better of using IF statements instead of CASE, which you can find an example of in my second link above.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: squil

Please Log in or Create an account to join the conversation.

  • squil
  • squil
  • OFFLINE
  • Posts: 42
  • Thanks: 1
  • Karma: 0
11 years 3 months ago #231538 by squil
Replied by squil on topic 'Case' in CB query
Thank you Krileon!!!!!!

This is query work correctly:

SELECT if(cb_towncheck='Иное', city, cb_towncheck) FROM `znaji_comprofiler` WHERE user_id ='[user_id]'
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum