2 Replies - 864 Views - Last Post: 23 April 2012 - 04:32 AM

#1 byrandomby1  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 124
  • Joined: 08-March 11

setting boolean values

Posted 22 April 2012 - 05:29 PM

update table
set bValue = value1 is not null
where id=1;


I want to set bValue to be true when value1 is not null, and false if value1 is null.
Is line 2 correct? If not how do I do it?
Is This A Good Question/Topic? 0
  • +

Replies To: setting boolean values

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8367
  • View blog
  • Posts: 31,093
  • Joined: 12-June 08

Re: setting boolean values

Posted 22 April 2012 - 05:44 PM

I am always a fan of 'isnull'.
Was This Post Helpful? 0
  • +
  • -

#3 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 782
  • View blog
  • Posts: 1,663
  • Joined: 30-January 09

Re: setting boolean values

Posted 23 April 2012 - 04:32 AM

I agree with modi123_1 thst ISNULL() is the way to go, but a a few words of warning for you.

Note that the MySQL ISNULL function has different syntax to the MSSQL ISNULL function (maybe not applicable in your case, but might be useful to someone who finds this via Google).

Also of note is that there is no native boolean type in MySQL as of v5.5. BOOLEAN is synonymous with TINYINT(1). So, any value you want to store that is boolean, will actually be stored as 0/1, not false/true. In PHP, this isn't a real problem with most applications, but something worthy of note, espacially if you're pushing values between languages with strong typing.

This post has been edited by e_i_pi: 23 April 2012 - 04:38 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1