Results 1 to 3 of 3

Thread: Should be simple....

  1. #1
    Join Date
    Dec 2005
    Queen Creek, AZ

    Should be simple....

    Ok, so I am adding data to a field.
    If the field is null add a value. If the field is not null, add the value prepended with a comma.

    So I tried this to make sure it worked, but it doesn't:
    SELECT IF(IS NULL(`vg_user_data`.`friends_list`), '2', ',2')
    The above was just for a simple test, not the statemnet I would use.

    Now why would that not work?

    If 'IS NULL' returns true, select '2' else select ',2'.

    Problem is I get this error every time:
    #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 'IS NULL(`vg_user_data`.`friends_list`), '2', ',2')' at line 1
    I could check the field first, but why use two db calls when I should be able to do it in one?!

    Thanks for any help.

    Last edited by CrazyMerlin; 02-26-2007 at 12:21 AM.

  2. #2
    Join Date
    Dec 2005
    Queen Creek, AZ
    Okay forget the above....doh!

    IS NULL is not a function....doh!

    UPDATE `vg_user_data`
    SET `friends_list` = IF(`friends_list` IS NULL, '3', CONCAT(`friends_list`, ',3'))
    WHERE `user_idx` = 1
    is what I needed!
    Last edited by CrazyMerlin; 02-26-2007 at 12:30 AM.

  3. #3
    Join Date
    Dec 2006
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    IFNULL() is perhaps what you where looking for...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles