ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Compare Comma Separated (Delimited) values in SQL QueryHi @Amit,<br />Please try the following<br /><br /><a href = 'link(Threads/848692/Check-whether-some-string-exists-in-a-comma-separated-string-using-C-Net/)'>Check whether some string exists in a comma separated string using C# .Net</a><br /><br />It might help you.<br /><br />Cheers Andrea.https://www.aspforums.net:443/Threads/160390/Compare-Comma-Separated-Delimited-values-in-SQL-Query/https://www.aspforums.net:443/Threads/160390/Compare-Comma-Separated-Delimited-values-in-SQL-Query/Wed, 17 Oct 2018 02:47:06 GMTCompare Comma Separated (Delimited) values in SQL Query<p>I wanna SQL Querry and that too not with contains keyword. Also both left and right contains comma separated string.</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/160390/Compare-Comma-Separated-Delimited-values-in-SQL-Query/https://www.aspforums.net:443/Threads/160390/Compare-Comma-Separated-Delimited-values-in-SQL-Query/Wed, 17 Oct 2018 02:49:24 GMTCompare Comma Separated (Delimited) values in SQL Query<p>Hi <a class="username" rel="Amit">Amit</a>,</p> <p>Check this sample query and correct your query by refering it.</p> <p>For split string function refer below article.</p> <h1 class="header"><a title="Split function in SQL Server Example: Function to Split Comma separated (Delimited) string in SQL Server 2005, 2008 and 2012'a" href="https://www.aspsnippets.com/Articles/Split-function-in-SQL-Server-Example-Function-to-Split-Comma-separated-Delimited-string-in-SQL-Server-2005-2008-and-2012.aspx">Split function in SQL Server Example: Function to Split Comma separated (Delimited) string in SQL Server 2005, 2008 and 2012</a></h1> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">DECLARE @Test AS TABLE(SiNo INT,ColumnName VARCHAR(100)) INSERT INTO @Test VALUES(1,&#39;sumit,sanjay,amit,ajay&#39;) INSERT INTO @Test VALUES(2,&#39;amit,sumit,sanjay&#39;) INSERT INTO @Test VALUES(3,&#39;amit,sumit,akshay&#39;) DECLARE @CommaString VARCHAR(50), @stringCount INT SET @CommaString = &#39;amit,sanjay,sumit&#39; SELECT @stringCount = COUNT(Item) FROM dbo.SplitString(@CommaString,&#39;,&#39;) DECLARE @Result VARCHAR(MAX) SELECT @Result = COALESCE(@Result + &#39; and &#39; ,&#39;&#39;) + CONVERT(VARCHAR(20),SiNo) FROM (SELECT SiNo FROM ( SELECT CASE WHEN COUNT(SiNo) = @stringCount THEN SiNo END SiNo FROM ( SELECT t.SiNo,x.Item FROM @Test t CROSS APPLY(SELECT Item FROM dbo.SplitString(t.ColumnName,&#39;,&#39;)) x ) a WHERE a.Item IN (SELECT Item FROM dbo.SplitString(@CommaString,&#39;,&#39;)) GROUP BY SiNo) f WHERE f.SiNo IS NOT NULL)g SELECT &#39;&#39;&#39;&#39;+ @CommaString + &#39;&#39;&#39; is exist in Sl.No &#39; + @Result Result</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1"> <tbody> <tr><th>Result</th></tr> <tr> <td>'amit,sanjay,sumit' is exist in Sl.No 1 and 2</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/160390/Compare-Comma-Separated-Delimited-values-in-SQL-Query/https://www.aspforums.net:443/Threads/160390/Compare-Comma-Separated-Delimited-values-in-SQL-Query/Wed, 17 Oct 2018 06:30:17 GMT