View Single Post
  #2 (permalink)  
Old 05-24-2006, 11:48 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 91
ben has disabled reputation
Default MySQL answer. Re: How do i perform an If statement on a cloumn?

Yes you can do that.
Here is an example that will check wether a colum "is_valid", which stores an integer value of 1 (for YES) or 0 for (NO), is valid or not and return the string YES or NO accordingly.

[sql]
SELECT
id,
IF(is_valid = 1, 'YES', 'NO') as is_valid
FROM test_table
[/sql]

In your case you just want to check if the a column (say "test_column") has a value or not so it will look something like:

[sql]
SELECT,
id,
IF ( test_column = '', 'FALSE', 'TRUE') as test_column
FROM test_table
[/sql]

The column "test_column" must be NOT NULL. If it allows NULLs you could check for that:

[sql]
IF(test_column IS NULL, 'FALSE', IF(test_column = '', 'FALSE', 'TRUE')) as test_column
[/sql]
Reply With Quote