﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Using ROW_COUNT / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 18:09:58 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Using ROW_COUNT</title><link>http://www.sqlservercentral.com/Forums/Topic1358078-391-1.aspx</link><description>You might also want to have a read through this: [url]http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/[/url]</description><pubDate>Thu, 13 Sep 2012 03:22:27 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: Using ROW_COUNT</title><link>http://www.sqlservercentral.com/Forums/Topic1358078-391-1.aspx</link><description>Nope thats absolutely fine.  I just wanted a way to return the total number of rows to php for pagination.  Perfect thanks very much</description><pubDate>Thu, 13 Sep 2012 02:58:30 GMT</pubDate><dc:creator>mark.dungey 56406</dc:creator></item><item><title>RE: Using ROW_COUNT</title><link>http://www.sqlservercentral.com/Forums/Topic1358078-391-1.aspx</link><description>May not be what you're after, but you can return an additional column with the total row count[code="sql"]Alter proc [dbo].[InvoiceDisplayTest] (@InvoiceNumber nvarchar(50),@InvoiceDate datetime ,@InvoiceDate1 datetime, @AccountNumber nvarchar(50),@TradingPartnerID nvarchar(50),@Page nvarchar(50),@rownum int OUTPUT)ASBEGINSELECT * FROM (SELECT InvoiceID,DocumentNumber, convert(char(12),DocumentDate,112) AS DocumentDate,AccountNumber,Supplier,TradingPartnerID, ROW_NUMBER()OVER(ORDER BY DocumentNumber ASC)AS rowno,COUNT(*) OVER() AS TotalRows FROM InvoiceHeaderWHERE (@InvoiceNumber = '' OR DocumentNumber = @InvoiceNumber)and(@AccountNumber = '' or AccountNumber = @AccountNumber)and(@TradingPartnerID = '' or TradingPartnerID = @TradingPartnerID)and(@InvoiceDate = '' or DocumentDate &amp;gt;= @InvoiceDateandDocumentDate &amp;lt;=@InvoiceDate1 or @InvoiceDate1 = ''))As qrWHERE rowno BETWEEN ((@Page - 1) * 20 + 1)AND (@Page * 20)END[/code]</description><pubDate>Thu, 13 Sep 2012 02:38:15 GMT</pubDate><dc:creator>Mark-101232</dc:creator></item><item><title>RE: Using ROW_COUNT</title><link>http://www.sqlservercentral.com/Forums/Topic1358078-391-1.aspx</link><description>Hi thanks for the reply. Unfortunately that just returns the row count of the rows that i have asked for i.e always 20 as thats the limit i've set.  Any other suggestions:-D</description><pubDate>Thu, 13 Sep 2012 02:22:43 GMT</pubDate><dc:creator>mark.dungey 56406</dc:creator></item><item><title>RE: Using ROW_COUNT</title><link>http://www.sqlservercentral.com/Forums/Topic1358078-391-1.aspx</link><description>Give this a try:[code="sql"]Alter proc [dbo].[InvoiceDisplayTest] (    @InvoiceNumber nvarchar(50),    @InvoiceDate datetime ,    @InvoiceDate1 datetime,     @AccountNumber nvarchar(50),    @TradingPartnerID nvarchar(50),    @Page nvarchar(50),    @rownum int OUTPUT)ASBEGIN    SELECT *    FROM (SELECT InvoiceID,DocumentNumber, convert(char(12),DocumentDate,112) AS DocumentDate,AccountNumber,Supplier,TradingPartnerID,           ROW_NUMBER()OVER(ORDER BY DocumentNumber ASC)AS rowno          FROM InvoiceHeader          WHERE            (@InvoiceNumber = '' OR DocumentNumber = @InvoiceNumber)            and (@AccountNumber = '' or AccountNumber = @AccountNumber)            and (@TradingPartnerID = '' or TradingPartnerID = @TradingPartnerID)            and (@InvoiceDate = '' or DocumentDate &amp;gt;= @InvoiceDate            and DocumentDate &amp;lt;=@InvoiceDate1 or @InvoiceDate1 = '')         )As qr    WHERE        rowno BETWEEN ((@Page - 1) * 20 + 1)        AND (@Page * 20)    SET @rownum = @@rowcount;END[/code]</description><pubDate>Wed, 12 Sep 2012 09:59:33 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>Using ROW_COUNT</title><link>http://www.sqlservercentral.com/Forums/Topic1358078-391-1.aspx</link><description>Hi Below is the code for my stored procedureAlter proc [dbo].[InvoiceDisplayTest] (@InvoiceNumber nvarchar(50),@InvoiceDate datetime ,@InvoiceDate1 datetime, @AccountNumber nvarchar(50),@TradingPartnerID nvarchar(50),@Page nvarchar(50),@rownum int OUTPUT)ASBEGINSELECT * FROM (SELECT InvoiceID,DocumentNumber, convert(char(12),DocumentDate,112) AS DocumentDate,AccountNumber,Supplier,TradingPartnerID, ROW_NUMBER()OVER(ORDER BY DocumentNumber ASC)AS rowno FROM InvoiceHeaderWHERE (@InvoiceNumber = '' OR DocumentNumber = @InvoiceNumber)and(@AccountNumber = '' or AccountNumber = @AccountNumber)and(@TradingPartnerID = '' or TradingPartnerID = @TradingPartnerID)and(@InvoiceDate = '' or DocumentDate &amp;gt;= @InvoiceDateandDocumentDate &amp;lt;=@InvoiceDate1 or @InvoiceDate1 = ''))As qrWHERE rowno BETWEEN ((@Page - 1) * 20 + 1)AND (@Page * 20)ENDMy Question is how do I SET my @rownum OUTPUT parameter equal to the total rows for the inner select statement. As the rows for the whole query only counts the ones being displayed. Cant i just use the alias of my ROW_NUMBER() to get the total rows. Or another way.Looking foward to hearing from youMark</description><pubDate>Wed, 12 Sep 2012 09:51:55 GMT</pubDate><dc:creator>mark.dungey 56406</dc:creator></item></channel></rss>