Hi.
On Tue, Aug 14, 2001 at 01:31:04PM -0700, [EMAIL PROTECTED] wrote:
> I am trying to do a nested if, but it appears to break my query...
> Here is a sample of what I am trying to, basically validating email
> addresses out of a db:
>
> select IF( (LENGTH( emailaddr ) <= 1 ||
> NOT LOCATE( "\@",emailaddr ) ||
> LOCATE( " ",emailaddr ),
> (IF address.ts >= 20010813000000,
> CONCAT( login, "\@blah.com ),
> CONCAT( login, "\@crap.com )),
> emailaddr AS email FROM logintable WHERE eid = $id;
>
> Basically, I check to see if the email address is not null and
> greater than 1 character in length, if there is an "@" sign in it,
> and that there aren't any spaces in it. If it fails those three
> tests, I check the timestamp of a record, and append one of two
> different domains to the login. This worked before with just the
> "concat ... blah.com" line as expr2 of the if statement, but when I
> try to make expr2 an "if" statement itself, it breaks.
As a principle, please quote any error message you got.
> Can anyone tell me if nested ifs aren't allowed, or is my syntax
> just flat out wrong?
First, the statement above has 7 opening brackets, but only 6 closing
ones and some closing quotation marks are missing.
Second, the above statement (at the second IF) ignores the fact that
IF is a function with a parameter list and has to be written as
IF(condition,do1,do2) where 'do2' can be left away, i.e.
SELECT IF( LENGTH( emailaddr ) <= 1 ||
NOT LOCATE( "\@",emailaddr ) ||
LOCATE( " ",emailaddr )
,
IF( address.ts >= 20010813000000,
CONCAT( login, "\@blah.com" ),
CONCAT( login, "\@crap.com" ) )
),
emailaddr AS email
FROM logintable
WHERE eid = $id;
Bye,
Benjamin.
---------------------------------------------------------------------
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