Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql state ment to select the row that not is email address in mysql

Posted on 2011-02-12
2
Medium Priority
?
274 Views
Last Modified: 2012-05-11
I have a column email (varchar)
how can I select  rows that column "email" is not email
0
Comment
Question by:teera
2 Comments
 
LVL 3

Accepted Solution

by:
sunezapa earned 2000 total points
ID: 34881101
I would consider to do the check in frontend code.

But by SQL you can check some elements of "valid email"-rules, here I found example:

--No embedded spaces
- '@' can't be the first character of an email address
- '.' can't be the last character of an email address
- There must be a '.' somewhere after '@'
- the '@' sign is allowed
- Domain name should end with at least 2 character extension
- can't have patterns like '.@' and '..'

SELECT email_address WHERE NOT (
     CHARINDEX(' ',LTRIM(RTRIM(@email_address))) = 0 
AND  LEFT(LTRIM(@email_address),1) <> '@' 
AND  RIGHT(RTRIM(@email_address),1) <> '.' 
AND  CHARINDEX('.',@email_address ,CHARINDEX('@',@email_address)) - CHARINDEX('@',@email_address ) > 1 
AND  LEN(LTRIM(RTRIM(@email_address ))) - LEN(REPLACE(LTRIM(RTRIM(@email_address)),'@','')) = 1 
AND  CHARINDEX('.',REVERSE(LTRIM(RTRIM(@email_address)))) >= 3 
AND  (CHARINDEX('.@',@email_address ) = 0 AND CHARINDEX('..',@email_address ) = 0)
)

Open in new window


0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 34882139
Fetch your row and check the fetched record is valid email or not.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question