Syntax error in SQL Server Function

I'm pretty new to SQL, especially creating SQL Funcitons. I getting a syntax error when I try to compile this function in the SSMS.

USE [JTSConversion]
GO
/****** Object:  UserDefinedFunction [dbo].[isALetter]   Script Date: 2/2/2018 2:30:26 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


Create FUNCTION [dbo].[isALetter] (@passedString varchar (1)) 
					RETURNS varchar(1)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @Answer   varchar(1)
	DECLARE @strUCase varchar(1)

	set @Answer='N'    -- false

	Set @strUCase = upper(@passedString)

If @strUCase = ‘A’ Or @strUCase = ‘B’ Or @strUCase = ‘C’ Or @strUCase = ‘D’ Or @strUCase = ‘E’ Or 
   @strUCase = ‘F’ Or @strUCase = ‘G’ Or @strUCase = ‘H’ Or @strUCase = ‘I’ Or @strUCase = ‘J’ Or 
   @strUCase = ‘K’ Or @strUCase = ‘L’ Or @strUCase = ‘M’ Or @strUCase = ‘N’ Or @strUCase = ‘O’ Or 
   @strUCase = ‘P’ Or @strUCase = ‘Q’ Or @strUCase = ‘R’ Or @strUCase = ‘S’ Or @strUCase = ‘T’ Or 
   @strUCase = ‘U’ Or @strUCase = ‘V’ Or @strUCase = ‘W’ Or @strUCase = ‘X’ Or @strUCase = ‘Y’ Or 
   @strUCase = ‘Z’ 
    set @Answer='Y'

	return @Answer

END

Open in new window


The error is:
Msg 102, Level 15, State 1, Procedure isALetter, Line 22
Incorrect syntax near '‘'.

Line 22 is
If @strUCase = ‘A’ Or @strUCase = ‘B’ Or @strUCase = ‘C’ Or @strUCase = ‘D’ Or @strUCase = ‘E’ Or

I don't see it.  Can anyone spot the syntax error?
LVL 1
mlcktmguyAsked:
Who is Participating?
 
Scott PletcherSenior DBACommented:
Don't see the syntax error off hand, but you could use a lot less code to get the result:


CREATE FUNCTION [dbo].[isALetter] (@passedString varchar (1))
                              RETURNS varchar(1)
AS
BEGIN
RETURN (
    SELECT CASE WHEN UPPER(@passedString) LIKE '[A-Z]'
        THEN 'Y' ELSE 'N' END AS answer
)
END
0
 
Garfield SamuelsProject ManagerCommented:
It seems to have an issue with your closing quote mark.  Try replacing them with regular quotes or the same ones you use for opening the quotes.
0
 
ste5anSenior DeveloperCommented:
Only the single quote ' is allowed as text delimiter. Not other apostroph symboles like ´`.
0
 
mlcktmguyAuthor Commented:
Wow, so much to learn.  Thanks for the much better approach.

Not sure what the original syntax error was but all of the text delimiters were already single quotes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.