Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SQL CASE

Featured Replies

hello me again with yet another sql query issue :unsure:

 

ive using this case to swap 0's with 1's and visa versa if the type is not R im using this at the moment

 

CASE `orig_val`
        WHEN `orig_val` = 1 THEN "0"
        WHEN `orig_val` = 0 THEN "1"
        WHEN `type` = "R" THEN `orig_val`    
END as `value`
but the above code always returns 0 not sure why

Edited by D4Y0

 

hello me again with yet another sql query issue :unsure:

 

ive using this case to swap 0's with 1's and visa versa if the type is not R im using this at the moment

 

CASE `orig_val`
        WHEN `orig_val` = 1 THEN "0"
        WHEN `orig_val` = 0 THEN "1"
        WHEN `type` = "R" THEN `orig_val`    
END as `value`
but the above code always returns 0 not sure why

 

so your orig_val can hold 1,0

and type can hold 'R'

 

So 1 becomes 0 and 0 becomes 1.

 

But you are not comparing "type" just orig_val" in the case switch ?

 

I think i that's right, I could be totally wrong, but that's the logic i have come to.

  • Author

Yea pretty much I fixes it by doing the case on the type and then if type = T it would minus the value from 1, for some reason it didn't like having 0 in the case]

 

Example:

case `type`
   WHEN "T" THEN 1-val
   ELSE val
END
That way 1-1 = 0 and 1-0 = 1 and it was much less code, dont know why i ever post on here as as soon as i post i usualy find the awnser 10 mins later :p

Edited by D4Y0

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.