ALTER FUNCTION [dbo].[Contains_Arabic_English_Char] ( @RowStr nvarchar(1000) )
RETURNS Char
AS
BEGIN
declare @index int;
declare @charac char(1);
SELECT @index = 0;
declare @thisChar char(1);
while(@index <= LEN(@RowStr))
begin
SELECT @thisChar = SUBSTRING(@RowStr,@index,1);
-- print @index
-- print ASCII(@thisChar)
if (AS开发者_JAVA百科CII(@thisChar) BETWEEN 153 and 158 OR ASCII(@thisChar) BETWEEN 162 and 218 OR ASCII(@thisChar) BETWEEN 223 and 254 )
--if (unicode(@thisChar) BETWEEN U+0600 and U+06FF)
begin SELECT @index=-1;
BREAK;
end
else
SELECT @index=@index+1;
end
-- print @index
-- print LEN(@rowStr)
if (@index =-1)
BEGIN
SET @charac = 'A' --''found a Arabic char!'
END
ELSE
BEGIN
SET @charac = 'E' --'no Arabic Char found!' END
RETURN @charac
END
EXEC select [dbo].[Contains_Arabic_English_Char] ('ش')
it was showing ouput As "E"
so i have checked up like this manner
select ascii('ش')
it was given output as 63
63 is nothng but ascii value for Question mark '?"
Try using UNICODE() instead of ASCII(), because you're dealing with unicode characters.
ASCII():
Returns the ASCII code value of the leftmost character of a character expression.
UNICODE():
Returns the integer value, as defined by the Unicode standard, for the first character of the input expression.
Note, to run a test:
-- Returns 63:
select ASCII('ش')
-- Still returns 63:
select UNICODE('ش')
-- Returns 1588. Note the N before the character, to indicate it's a unicode string
select UNICODE(N'ش')
Update: A few things you need to change:
declare @thisChar char(1);
should be:
declare @thisChar nchar(1);
Then when you check that character, just do a straight swap from using ASCII() to UNICODE()
精彩评论