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.Query to Skip rows if Column value is NULL in SQL Server<p>Hi&nbsp;satabeach,</p> <p>Refer below query.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">DECLARE @Test AS TABLE(itId INT,itemName VARCHAR(20)) INSERT INTO @Test VALUES(1,&#39;Apple&#39;) INSERT INTO @Test VALUES(2,&#39;pencil&#39;) INSERT INTO @Test VALUES(3,&#39;Mango&#39;) INSERT INTO @Test VALUES(4,&#39;pencil&#39;) INSERT INTO @Test VALUES(5,&#39;Banana&#39;) INSERT INTO @Test VALUES(6,&#39;&#39;) INSERT INTO @Test VALUES(7,&#39;Peach&#39;) INSERT INTO @Test VALUES(8,&#39;Stawbery&#39;) SELECT * FROM @Test WHERE itId BETWEEN 3 AND 6 AND ISNULL(itemName,&#39;&#39;) &lt;&gt; &#39;&#39;</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1"> <tbody> <tr><th>itId</th><th>itemName</th></tr> <tr> <td>3</td> <td>Mango</td> </tr> <tr> <td>4</td> <td>pencil</td> </tr> <tr> <td>5</td> <td>Banana</td> </tr> </tbody> </table> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/113121/Query-to-Skip-rows-if-Column-value-is-NULL-in-SQL-Server/https://www.aspforums.net:443/Threads/113121/Query-to-Skip-rows-if-Column-value-is-NULL-in-SQL-Server/Mon, 13 May 2019 02:58:35 GMTQuery to Skip rows if Column value is NULL in SQL Server<p>Refer below query.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">DECLARE @Test AS TABLE(itId INT,itemName VARCHAR(20)) INSERT INTO @Test VALUES(1,&#39;Apple&#39;) INSERT INTO @Test VALUES(2,&#39;pencil&#39;) INSERT INTO @Test VALUES(3,&#39;Mango&#39;) INSERT INTO @Test VALUES(4,&#39;pencil&#39;) INSERT INTO @Test VALUES(5,&#39;Banana&#39;) INSERT INTO @Test VALUES(6,&#39;&#39;) INSERT INTO @Test VALUES(7,&#39;Peach&#39;) INSERT INTO @Test VALUES(8,&#39;Stawbery&#39;) DECLARE @Min INT,@Max INT SET @Min = 3 SET @Max = ((SELECT itId FROM @Test WHERE ISNULL(itemName,&#39;&#39;) = &#39;&#39;) - 1) SET @Max = COALESCE(NULLIF(@Max,&#39;&#39;), @Max, @Min + 6) SELECT TOP 6 * FROM @Test WHERE itId BETWEEN @Min AND @Max</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <table border="1"> <tbody> <tr><th>itId</th><th>itemName</th></tr> <tr> <td>3</td> <td>Mango</td> </tr> <tr> <td>4</td> <td>pencil</td> </tr> <tr> <td>5</td> <td>Banana</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/113121/Query-to-Skip-rows-if-Column-value-is-NULL-in-SQL-Server/https://www.aspforums.net:443/Threads/113121/Query-to-Skip-rows-if-Column-value-is-NULL-in-SQL-Server/Tue, 14 May 2019 03:33:50 GMT