Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This works for your examples, just don't know if it's faster than your solution.</p> <p>The code should be pretty self explanatory and easy to change</p> <pre><code>DECLARE @str1 VARCHAR(max) DECLARE @str2 VARCHAR(max) SELECT @str1 = 'Patel; Raj' SELECT @str2 = 'Patel' DECLARE @x1 XML DECLARE @x2 XML SELECT @x1 = CAST('&lt;i&gt;' + REPLACE(@str1, ',', '&lt;/i&gt;&lt;i&gt;') + '&lt;/i&gt;' AS XML) SELECT @x2 = CAST('&lt;i&gt;' + REPLACE(@str2, ',', '&lt;/i&gt;&lt;i&gt;') + '&lt;/i&gt;' AS XML) SELECT COUNT(*) FROM ( SELECT p.number as Position, LTRIM(RTRIM(x.value('.','VARCHAR(50)'))) AS Name FROM master..spt_values p cross APPLY @x1.nodes('/i[position()=sql:column("number")]') n(x) where p.type = 'p' ) Names1 INNER JOIN ( SELECT p.number as Position, LTRIM(RTRIM(x.value('.','VARCHAR(50)'))) AS Name FROM master..spt_values p cross APPLY @x2.nodes('/i[position()=sql:column("number")]') n(x) where p.type = 'p' ) Names2 ON Names1.Name = Names2.Name OR (LTRIM(RTRIM(PARSENAME(Replace(Names1.Name,';','.'),1))) = LTRIM(RTRIM(PARSENAME(Replace(Names2.Name,';','.'),1))) AND LTRIM(RTRIM(PARSENAME(Replace(Names1.Name,';','.'),2))) = LTRIM(RTRIM(PARSENAME(Replace(Names2.Name,';','.'),2))) ) OR (LTRIM(RTRIM(PARSENAME(Replace(Names1.Name,';','.'),2))) = LTRIM(RTRIM(PARSENAME(Replace(Names2.Name,';','.'),2))) AND LEFT(LTRIM(RTRIM(PARSENAME(Replace(Names1.Name,';','.'),1))),1) = LTRIM(RTRIM(PARSENAME(Replace(Names2.Name,';','.'),1))) ) OR (LTRIM(RTRIM(PARSENAME(Replace(Names1.Name,';','.'),2))) = LTRIM(RTRIM(PARSENAME(Replace(Names2.Name,';','.'),2))) AND LTRIM(RTRIM(PARSENAME(Replace(Names1.Name,';','.'),1))) = LEFT(LTRIM(RTRIM(PARSENAME(Replace(Names2.Name,';','.'),1))),1) ) OR Names1.Name = LTRIM(RTRIM(PARSENAME(Replace(Names2.Name,';','.'),2))) OR Names2.Name = LTRIM(RTRIM(PARSENAME(Replace(Names1.Name,';','.'),2))) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload