November 19, 2015 at 12:28 am
November 19, 2015 at 2:13 am
What about this
DECLARE @C NVARCHAR(10),@R NVARCHAR(10)
SELECT @C=replace(replace(N'1 2',char(9),' '),char(13),' ')
SELECT @r=replace(replace(N'12',char(9),' '),char(13),' ')
SELECT ASCII(@C),ASCII(@R)
IF @r=@C
BEGIN
SELECT 1
END
There are invisible characters in the @C variable: tab or endof line char.
Igor Micev,My blog: www.igormicev.com
November 19, 2015 at 2:58 am
Thanks Buddy...
November 19, 2015 at 3:41 am
Use UNICODE() instead of ASCII():
DECLARE @C NVARCHAR(10),@R NVARCHAR(10)
SELECT @C=N'12'
SELECT @r=N'12'
SELECT @C, UNICODE(@C), @r, UNICODE(@R)
-- don't forget that you are only comparing the first character of each string.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 19, 2015 at 7:27 pm
This is where a Tally Table is a good thing. I run into this kind of problem and want to know why 2 strings are not equal. This would probably make for a useful UDF.
DECLARE @C NVARCHAR(10) = N'12 ',
@r NVARCHAR(10) = N'12';
WITH
L1 AS (SELECT X FROM (VALUES (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) X(X)),
iTally(N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) FROM L1 a,L1 b,L1 c,L1 d)
SELECT TOP (CASE
WHEN DATALENGTH(@C) >= DATALENGTH(@R)
THEN DATALENGTH(@C) ELSE DATALENGTH(@R)
END)
Position = N,
c = SUBSTRING(@C,N,1),
r = SUBSTRING(@R,N,1),
cu = UNICODE(SUBSTRING(@C,N,1)),
ru = UNICODE(SUBSTRING(@R,N,1))
FROM iTally
WHERE ISNULL(UNICODE(SUBSTRING(@C,N,1)),-1) <> ISNULL(UNICODE(SUBSTRING(@R,N,1)),-1);
-- Itzik Ben-Gan 2001
November 24, 2015 at 2:01 am
Thanks Buddy,
But still issue exists as it fails when we compare normal strings.
DECLARE @C NVARCHAR(10),@R NVARCHAR(10)
SELECT @C=N'Ant'
SELECT @r=N'ant'
IF @r = @C COLLATE Latin1_General_Bin
SELECT 1
ELSE
SELECT 2
As per my understanding Latin1_General_Bin is case sensitive and I searching for case insensetive.
November 24, 2015 at 7:58 am
ningaraju.ne 46825 (11/24/2015)
Thanks Buddy,But still issue exists as it fails when we compare normal strings.
DECLARE @C NVARCHAR(10),@R NVARCHAR(10)
SELECT @C=N'Ant'
SELECT @r=N'ant'
IF @r = @C COLLATE Latin1_General_Bin
SELECT 1
ELSE
SELECT 2
As per my understanding Latin1_General_Bin is case sensitive and I searching for case insensetive.
Well, it would be nice if we know all the rules. Why is it "1" different from "1" but "a" is equal to "A"?
EDIT: By the way, I still believe that the appropriate collation is what's needed. Probably this one? Latin1_General_CI_AI_KS_WS (Latin1-General, case-insensitive, accent-insensitive, kanatype-sensitive, width-sensitive)
November 24, 2015 at 8:19 am
From Books Online (bold emphasis mine). Is this your problem?
ASCII (Transact-SQL)
Returns the ASCII code value of the leftmost character of a character expression.
--
Scott
November 24, 2015 at 8:31 am
Scott-144766 (11/24/2015)
From Books Online (bold emphasis mine). Is this your problem?ASCII (Transact-SQL)
Returns the ASCII code value of the leftmost character of a character expression.
Not really, he was warned of this five days ago 😉
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply