List:General Discussion« Previous MessageNext Message »
From:SGreen Date:November 28 2005 7:33pm
Subject:Re: How to use Logic in View Statment?
View as plain text  
Scott Klarenbach <doyouunderstand@stripped> wrote on 11/28/2005 01:58:22 
PM:

> I'd like to do the following in my view
> 
> select
>   fieldOne,
>   fieldTwo,
>   if(fieldThree.length>0) then fieldThree as Company
>   else fieldFour as Company
> 
> from table;
> 
> I realize this syntax isn't correct and length doesn't exists, but is
> this possible?  I've seen it done in SQLServer, but can't remember the
> syntax.
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
> 

LENGTH does exist (as a function):
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

and here is how to use the IF() function:
http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html

I believe this is the equivalent statement you wanted:

SELECT 
  fieldOne,
  fieldTwo,
  IF(CHAR_LENGTH(fieldThree)>0,fieldThree,fieldFour) as Company
FROM table;

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine
Thread
How to use Logic in View Statment?Scott Klarenbach28 Nov
  • Re: How to use Logic in View Statment?SGreen28 Nov
    • Re: How to use Logic in View Statment?Cory @ SkyVantage28 Nov
      • Re: How to use Logic in View Statment?SGreen28 Nov
    • Re: How to use Logic in View Statment?Martijn Tonies28 Nov
    • Re: How to use Logic in View Statment?Scott Klarenbach5 Dec
      • Re: How to use Logic in View Statment?SGreen5 Dec
  • Re: How to use Logic in View Statment?Peter Brawley28 Nov
RE: How to use Logic in View Statment?Gelu Gogancea28 Nov