When I run the following code examples: I get different results (Shown below). Please explain why I get a match in the second example? I must be missing some understanding.
print @@version
-- First example behaves as expected
declare @strSearch nvarchar(10) = 'x (20) ';
declare @definition nvarchar(100) = 'x (200000000) ';
print charindex(@strSearch, @definition);
go
-- Second example does not behave as expected
declare @strSearch nvarchar(10) = 'xrchar (20) ';
declare @definition nvarchar(100) = 'xrchar (200000000) ';
print charindex(@strSearch, @definition);
Results below: (0 'not found' and 1 'found'):
Microsoft SQL Server 2008 (SP3) - 10.0.5538.0 (X64) Apr 3 2015 14:50:02 Copyright (c) 1988-2008 Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (VM)
0 1