View Single Post

   
  #5 (permalink)  
Old 03-28-2008, 04:40 AM
worldcyclist@gmail.com
 
Posts: n/a
Default Re: SET value based on a condition


I did discover that this works...
SELECT IF(date<NOW(), 'Yes', expired) AS "expired", date FROM table;

I want to give a very public thank you for assisting me zeldorblat.
I'm always amazed at how willing people are to give of their
expertise.

JC


>
> > > > I have a table with two columns, "expired" and "date"
> > > > The data is like this...

>
> > > > SELECT expired, date FROM table
> > > > expired date
> > > > NO 01-01-2001
> > > > NO 01-01-2001

>
> > > > What I need to do is return an Expired value of "YES" if the date is
> > > > older than NOW().

>
> > > > I started messing around with If statements and have figured out how
> > > > to set a default in the same column that is being checked but am
> > > > stumped on this one. What I need, based on the above data is ...

>
> > > > SELECT expired, date FROM table
> > > > expired date
> > > > YES 01-01-2001
> > > > YES 01-01-2001

>
> > > > Any suggestions and I thank you profusely in advance.
> > > > JC

>
> > > select (case when date < now() then 'YES' else expired end) expired,
> > > date
> > > from table


Reply With Quote