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.Add multiple filters to dynamic query in SQL Server<p>Hey <a class="username" rel="nauna">nauna</a>,</p> <p>Please refer below 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),category VARCHAR(max)) INSERT INTO #animal VALUES(1,&#39;cat, dog,&#39;,&#39;pet&#39;) INSERT INTO #animal VALUES(2,&#39;tiger, safari,&#39;,&#39;wild&#39;) DECLARE @Key VARCHAR(200),@category VARCHAR(200) SET @Key = &#39;cat,&#39; SET @category = &#39;pet&#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;) AND category LIKE &#39;&#39;%&#39;+@category+&#39;%&#39;&#39;&#39;) DROP TABLE #animal</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <table border="1"> <tbody> <tr> <td><strong>ID</strong></td> <td><strong>type</strong></td> <td><strong>category</strong></td> </tr> <tr> <td>1</td> <td>cat, dog,</td> <td>pet</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/363942/Add-multiple-filters-to-dynamic-query-in-SQL-Server/https://www.aspforums.net:443/Threads/363942/Add-multiple-filters-to-dynamic-query-in-SQL-Server/Fri, 04 Jan 2019 04:45:09 GMT