SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to replace the return value of select?

    Hello!
    I know mysql has such function, but I can't find it.
    Let's say I have a column of type enum and it stores one of 3 possible values:

    'A', 'D', or 'U'

    What I want to do is the result of select to return either A or D or NULL instead of U
    basically this is an accecc control value -A for allow, D for deny and U for undefined. But I want the undefined to be returned as null

    Let's call my column 'access_control'
    so how should I write a select access_control from USER_GROUP?

    I hope someone knows exactly how to do this.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,819
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    SELECT CASE access_control WHEN 'A' THEN 'Allow' WHEN 'D' THEN 'Deny' ELSE NULL END FROM user_group
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, CASE!. Thank you.
    I was going to use REGEX.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •