Bluehost.com Web Hosting $6.95

using the result of conditional statements in where

This is a discussion on using the result of conditional statements in where within the MySQL Database forums, part of the Database Forums category; Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-31-2007
profke
 
Posts: n/a
Default using the result of conditional statements in where

Hi,

I'm trying to use the result of a conditional statement in a where
clause, but i'm getting 1)nowhere 2) desperate :-)

The query is simple:
--------
SELECT
idUser,
(@ageraw:=YEAR(CURRENT_DATE()) - YEAR(dateofbirth) -
(RIGHT(CURRENT_DATE(),5)<'12-31')) AS temp,
@age:=if( @ageraw > 100,0,
if( @ageraw < 10,0 ,
@ageraw
)) as age
from users u
---------

this works as a charm. But now I want to select users of a certain
age, and I add a where clause:
from users u having @age<50

This is not working. Nor is any other variant I can think of. How can
this be achieved?

greeting, and many thanks,

Paul

Reply With Quote
  #2 (permalink)  
Old 01-31-2007
Willem Bogaerts
 
Posts: n/a
Default Re: using the result of conditional statements in where

> @age:=if( @ageraw > 100,0,
> if( @ageraw < 10,0 ,
> @ageraw
> )) as age
>
> this works as a charm. But now I want to select users of a certain
> age, and I add a where clause:
> from users u having @age<50


As the fields is named "age", HAVING age<50 is what I would type. With
the @ character, you call the contents of the variable, not the contents
of a record field.

Best regards
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Reply With Quote
  #3 (permalink)  
Old 01-31-2007
profke
 
Posts: n/a
Default Re: using the result of conditional statements in where

Hi Willem

> As the fields is named "age", HAVING age<50 is what I would type. With
> the @ character, you call the contents of the variable, not the contents
> of a record field.


Thanks for your reply. However, that does not work :-((
I get a syntaxerror....

any more idea's?

Paul

Reply With Quote
  #4 (permalink)  
Old 01-31-2007
profke
 
Posts: n/a
Default Re: using the result of conditional statements in where

On 31 jan, 09:53, "profke" <pwieg...@gmail.com> wrote:
> Hi Willem
>
> > As the fields is named "age", HAVING age<50 is what I would type. With
> > the @ character, you call the contents of the variable, not the contents
> > of a record field.

>
> Thanks for your reply. However, that does not work :-((
> I get a syntaxerror....


Well, not a syntax error.. i get a unknown field error...

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0