www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  ODBC    Can you use CASE or IF in a SELECT statement to make a descision?
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
MF
Posted
How can you write a select statement that makes a decision based on the value of a field?

I've tried

SELECT CASE WHEN Title IS NULL THEN ' ' ELSE Title END FROM DatabaseName

but it complains that "Expected lexical element not found: FROM".

Any suggestions?
 
Posts: 5 | Registered: Tue August 21 2007Reply With QuoteEdit or Delete MessageReport This Post
MF
Posted Hide Post
I found a solution to my problem

SELECT {fn IFNULL(Title + ',','')} FROM Database

If the Title field is NULL, the concatenating NULL + ',' evaluates to NULL which means IFNULL will return the empty string ''.

If the Title field is not null, then concatenating Title + ',' evaluates to a string "This is the Title," which is returned by IFNULL
 
Posts: 5 | Registered: Tue August 21 2007Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  ODBC    Can you use CASE or IF in a SELECT statement to make a descision?