Gregg,
Tuesday, May 07, 2002, 12:15:27 AM, you wrote:

>> Check the manual:
>>       http://www.mysql.com/doc/V/a/Variables.html

GG> According to the manual from the above link, where it states:

GG> ==================================================
GG> You can set a variable with the SET syntax:
GG> SET @variable= { integer expression | real expression | string expression }
GG> [,@variable= ...].

GG> You can also assign a value to a variable in statements other than SET.
GG> However, in this case the assignment operator is := rather than =, because =
GG> is reserved for comparisons in non-SET statements:

GG> mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
GG> +----------------------+------+------+------+
GG> | @t1:=(@t2:=1)+@t3:=4 | @t1  | @t2  | @t3  |
GG> +----------------------+------+------+------+
GG> |                    5 |    5 |    1 |    4 |
GG> +----------------------+------+------+------+
GG> ==================================================

GG> mysql should be SET'ing the user variables in my query above. If mysql is
GG> processing the WHERE first and then the SELECT, shouldn't the user variables
GG> be set anyhow (even if the query returns an empty set)? For example:

GG> mysql> SELECT
GG>     ->    annual_filing.*,
GG>     ->    companies.name AS company_name,
GG>     ->    YEAR(filing_date) AS filing_year,
GG>     ->    @predictedYear := 1999 AS predictedYear,
GG>     ->    @earliestYear := 1996 AS earliestYear,
GG>     ->    @learnYear := 1998 AS learnYear
GG>     -> FROM
GG>     ->    annual_filing,
GG>     ->    companies
GG>     -> WHERE
GG>     ->       annual_filing.company_id = companies.ds_id
GG>     ->    AND
GG>     ->       YEAR(filing_date) <= @predictedYear
GG>     ->    AND
GG>     ->       YEAR(filing_date) >= @earliestYear;
GG> Empty set (25.89 sec)

GG> mysql> SELECT @predictedYear, @earliestYear, @learnYear;
GG> +----------------+---------------+------------+
GG> | @predictedYear | @earliestYear | @learnYear |
GG> +----------------+---------------+------------+
GG> | NULL           | NULL          | NULL       |
GG> +----------------+---------------+------------+
GG>
GG> 1 row in set (0.00 sec)
GG> ==================================================

     At first, you didn't initialized variables. So, variables @predictedYear
     and @earliestYear in your first SELECT statement are NULL. There
     are no records in tables, that meet these conditions and then
     SELECT does not initialize variables in the first part of the statement.

GG> ===
GG> Gregg Graubins <[EMAIL PROTECTED]>




-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Victoria Reznichenko
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
       <___/   www.mysql.com




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to