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.Select record using comma separated string in Like operator in SQL Server<p>Hey <a class="username" rel="nauna"> nauna</a>,</p> <p>Please refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">CREATE TABLE #animal (ID INT,type VARCHAR(max)) INSERT INTO #animal VALUES(1,&#39;cat, lion, donkey,&#39;) INSERT INTO #animal VALUES(2,&#39;tiger, safari,&#39;) DECLARE @Key VARCHAR(200) SET @Key = &#39;cat,tiger&#39; SELECT @Key = &#39;LIKE &#39;&#39;%&#39;+ REPLACE(@Key,&#39;,&#39;,&#39;%&#39;&#39; OR type LIKE &#39;&#39;%&#39;)+&#39;%&#39;&#39;&#39; EXEC(&#39;SELECT * FROM #animal WHERE type &#39;+ @Key +&#39;&#39;) DROP TABLE #animal</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table> <tbody> <tr> <td><strong>ID</strong></td> <td><strong>type</strong></td> </tr> <tr> <td>1</td> <td>cat, lion, donkey,</td> </tr> <tr> <td>2</td> <td>tiger, safari,</td> </tr> </tbody> </table> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/116536/Select-record-using-comma-separated-string-in-Like-operator-in-SQL-Server/https://www.aspforums.net:443/Threads/116536/Select-record-using-comma-separated-string-in-Like-operator-in-SQL-Server/Thu, 03 Jan 2019 05:12:38 GMT