Professional Web Applications Themes

using the result of conditional statements in where - MySQL

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 ...

  1. #1

    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

    profke Guest

  2. #2

    Default Re: using the result of conditional statements in where

    > age:=if( ageraw > 100,0, 

    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/
    Willem Guest

  3. #3

    Default Re: using the result of conditional statements in where

    Hi Willem
     

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

    any more idea's?

    Paul

    profke Guest

  4. #4

    Default Re: using the result of conditional statements in where

    On 31 jan, 09:53, "profke" <com> wrote: 
    >
    > Thanks for your reply. However, that does not work :-((
    > I get a syntaxerror....[/ref]

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

    profke Guest

Similar Threads

  1. If statements in PHP?
    By barbedwire103 in forum Dreamweaver AppDev
    Replies: 1
    Last Post: April 11th, 11:24 AM
  2. Conditional Statements in CDONTS
    By Mintyman in forum Dreamweaver AppDev
    Replies: 4
    Last Post: February 17th, 02:32 PM
  3. conditional sql statements
    By Bill in forum ASP
    Replies: 2
    Last Post: August 29th, 07:51 PM
  4. "OR" statements allowed in MultipleIf conditional regions in templates?
    By GGirlando webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 8
    Last Post: July 28th, 06:01 PM
  5. If/else statements - help.
    By Chris in forum PHP Development
    Replies: 1
    Last Post: June 28th, 01:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139