June 10, 2014 at 12:28 pm
Is there a limit on the size of the strings on both sides of the '=' sign for string comparison? If I have two varchar(max) strings, will the comparison be done beyond 8,000 characters?
June 10, 2014 at 12:36 pm
N_Muller (6/10/2014)
Is there a limit on the size of the strings on both sides of the '=' sign for string comparison? If I have two varchar(max) strings, will the comparison be done beyond 8,000 characters?
The string comparison done on the entire length of the string.
😎
USE tempdb;
GO
DECLARE @STR1 NVARCHAR(MAX) = N'';
DECLARE @STR2 NVARCHAR(MAX) = N'';
DECLARE @TSTR NVARCHAR(MAX) = REPLICATE('0',8000);
SELECT @STR1 = @TSTR + @TSTR + N'1'
SELECT @STR2 = @TSTR + @TSTR + N'1'
PRINT LEN(@STR1)
IF (@STR1 = @STR2)
BEGIN
PRINT 'EQUAL STRINGS!'
END
ELSE
BEGIN
PRINT 'NOT EQUAL STRINGS!'
END
SELECT @STR1 = @TSTR + @TSTR + N'1'
SELECT @STR2 = @TSTR + @TSTR + N'12'
PRINT LEN(@STR1)
IF (@STR1 = @STR2)
BEGIN
PRINT 'EQUAL STRINGS!'
END
ELSE
BEGIN
PRINT 'NOT EQUAL STRINGS!'
END
Output
16001
EQUAL STRINGS!
16001
NOT EQUAL STRINGS!
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply