vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| On Mar 20, 11:38 am, worldcycl...@gmail.com wrote: > 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 |
| |||
| This is giving me a syntax error. I'm on MySQL 5. I am wondering how this statement knows to set expired to "Yes". Hmmmm......... On Mar 20, 11:42 am, ZeldorBlat <zeldorb...@gmail.com> wrote: > On Mar 20, 11:38 am, worldcycl...@gmail.com wrote: > > > > > 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 |
| |||
| Let me correct myself... I am actually on MySQL 4.0.20 JC On Mar 20, 12:50 pm, worldcycl...@gmail.com wrote: > This is giving me a syntax error. I'm on MySQL 5. I am wondering how > this statement knows to set expired to "Yes". > Hmmmm......... > > On Mar 20, 11:42 am, ZeldorBlat <zeldorb...@gmail.com> wrote: > > > On Mar 20, 11:38 am, worldcycl...@gmail.com wrote: > > > > 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 |
| ||||
| 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 |