mlcktmguy
asked on
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.
The error is:
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?
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
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Only the single quote ' is allowed as text delimiter. Not other apostroph symboles like ´`.
ASKER
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.
Not sure what the original syntax error was but all of the text delimiters were already single quotes.