Update when email is in all caps

I have a field in my database called 'email', stores all emails for clients. When an email is sent out it works UNLESS the email is in all caps. For some reason in this scenario the email never makes it.

Can I run a script for this table "Users" and field "email" to turn all CAPS into non-caps ?

So if email is: NAME@DOMAIN.COM  changes to:  name@domain.com

OR even if it is : Name@DOMain.com changes to: name@domain.com

THx
LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Use the LOWER function to convert to lower case
Declare @email varchar(100) 

SELECT @email = 'NAME@DOMAIN.COM'
SELECT LOWER(@email)

SELECT @email = 'Name@DOMain.com'
SELECT LOWER(@email)  

Open in new window

So to change for an entire table
UPDATE Users
SET Email = LOWER(Email)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
I will try this:

UPDATE Users
SET email = LOWER(Email)

Thanks.
0
Scott PletcherSenior DBACommented:
Easiest and cleanest is probably to add a trigger to the table to insure that all inserted and updated emails are in lower case:


CREATE TRIGGER Users__Trg_Set_Email_Lower_Case
ON dbo.Users
AFTER INSERT, UPDATE
AS
SET NOCOUNT ON
UPDATE u
SET email = LOWER(u.email)
FROM dbo.Users u
INNER JOIN inserted i ON i.email = u.email
GO
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

AleksAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for amucinobluedot's comment #a39528709

for the following reason:

Works perfectly, thanks !
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Curiosity overwhelms me ... if it 'works perfectly', then wouldn't you want to accept an answer to this question, and not request it be deleted by accepting one of your own comments?
0
AleksAuthor Commented:
It apparently was a mistake on the comment that I accepted as answer.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim

btw Scott brings up a valid point, if this columns should always be small letters only, and this isn't be handled in any front-end, might as well enforce it when the rows are added to the table with a trigger.
0
AleksAuthor Commented:
Yes, I took care of that :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.