Solved

Error when using Case statement in SQL View

Posted on 2011-02-10
5
254 Views
Last Modified: 2012-06-27
I'm trying to use a CASE statement in my SQL View.

I keep getting the following error; can't figure out what is wrong with my code.

Error message: Incorrect Syntax near ''.
SELECT     

CASE WHEN Right(Email, 5) = ‘a.com’

THEN

LEFT(Email, LEN(Email) - 21) + UPPER(SUBSTRING(Email, LEN(Email) - 20, 1)) + SUBSTRING(Email, LEN(Email) - 19, 6) + UPPER(SUBSTRING(Email, 
                      LEN(Email) - 13, 1)) + SUBSTRING(Email, LEN(Email) - 12, 6) + UPPER(SUBSTRING(Email, LEN(Email) - 6, 1)) + RIGHT(Email, 6) 

ELSE 

LEFT(Email, LEN(Email) - 11) + UPPER(SUBSTRING(Email, LEN(Email) - 10, 1))  + SUBSTRING(Email, LEN(Email) - 9, 2) 
 + UPPER(SUBSTRING(Email, LEN(Email) - 7, 1))  + Right(Email,7)

AS Email

FROM         dbo.AD_List

Open in new window

0
Comment
Question by:imstac73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 34866750
SELECT     

CASE WHEN Right(Email, 5) = 'a.com'

THEN

LEFT(Email, LEN(Email) - 21) + UPPER(SUBSTRING(Email, LEN(Email) - 20, 1)) + SUBSTRING(Email, LEN(Email) - 19, 6) + UPPER(SUBSTRING(Email, 
                      LEN(Email) - 13, 1)) + SUBSTRING(Email, LEN(Email) - 12, 6) + UPPER(SUBSTRING(Email, LEN(Email) - 6, 1)) + RIGHT(Email, 6) 

ELSE 

LEFT(Email, LEN(Email) - 11) + UPPER(SUBSTRING(Email, LEN(Email) - 10, 1))  + SUBSTRING(Email, LEN(Email) - 9, 2) 
 + UPPER(SUBSTRING(Email, LEN(Email) - 7, 1))  + Right(Email,7)

end AS Email

FROM         dbo.AD_List

Open in new window

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 34867810
I think you mean:
Incorrect syntax near '‘'.
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 34868145
Try this:


SELECT    

CASE Email WHEN Right(Email, 5) = ‘a.com’

THEN

LEFT(Email, LEN(Email) - 21) + UPPER(SUBSTRING(Email, LEN(Email) - 20, 1)) + SUBSTRING(Email, LEN(Email) - 19, 6) + UPPER(SUBSTRING(Email,
                      LEN(Email) - 13, 1)) + SUBSTRING(Email, LEN(Email) - 12, 6) + UPPER(SUBSTRING(Email, LEN(Email) - 6, 1)) + RIGHT(Email, 6)

ELSE

LEFT(Email, LEN(Email) - 11) + UPPER(SUBSTRING(Email, LEN(Email) - 10, 1))  + SUBSTRING(Email, LEN(Email) - 9, 2)
 + UPPER(SUBSTRING(Email, LEN(Email) - 7, 1))  + Right(Email,7)

AS Email

FROM         dbo.AD_List
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 34868167
agarwalrahul,

Just out of curiousity, did you actually test that?
0
 

Author Comment

by:imstac73
ID: 34890706
agarwalrahul,, didn't work.  Incorrect syntax near '='.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

740 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