<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Private: Code &#38; Script Snippet &#187; DATABASE</title>
	<atom:link href="http://dev.kratik.net/index.php/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.kratik.net</link>
	<description>Every thing you imagin, study it - know it - use it</description>
	<lastBuildDate>Thu, 24 Jun 2010 08:30:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sql Server Tip 3</title>
		<link>http://dev.kratik.net/index.php/2010/03/09/sql-server-tip-3/</link>
		<comments>http://dev.kratik.net/index.php/2010/03/09/sql-server-tip-3/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 02:33:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>
		<category><![CDATA[sql server 2005]]></category>

		<guid isPermaLink="false">http://dev.kratik.net/?p=860</guid>
		<description><![CDATA[<p>Tip#3: Try to use CAST instead of CONVERT. CAST is ANSI-92 standard but CONVERT works in MS SQL server only. Also, some CONVERT styles may be deprecated in future MS SQL releases.</p>
]]></description>
			<content:encoded><![CDATA[<p>Tip#3: Try to use CAST instead of CONVERT. CAST is ANSI-92 standard but CONVERT works in MS SQL server only. Also, some CONVERT styles may be deprecated in future MS SQL releases.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2010/03/09/sql-server-tip-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to reset Identity Increment value in MS SQL</title>
		<link>http://dev.kratik.net/index.php/2008/10/30/how-to-reset-identity-increment-value-in-ms-sql/</link>
		<comments>http://dev.kratik.net/index.php/2008/10/30/how-to-reset-identity-increment-value-in-ms-sql/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 07:14:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/?p=457</guid>
		<description><![CDATA[<p>Sometimes we wish to get rid of all the data in a table. One way of doing this is with DROP TABLE, which we saw in the last section. But what if we wish to simply get rid of the data but not the table itself? For this, we can use the TRUNCATE TABLE command. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we wish to get rid of all the data in a table. One way of doing this is with DROP TABLE, which we saw in the last section. But what if we wish to simply get rid of the data but not the table itself? For this, we can use the TRUNCATE TABLE command. The syntax for TRUNCATE TABLE is</p>
<p>TRUNCATE TABLE &#8220;table_name&#8221;</p>
<p>So, if we wanted to truncate the table called customer that we created in SQL CREATE TABLE, we simply type,</p>
<p>TRUNCATE TABLE customer</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2008/10/30/how-to-reset-identity-increment-value-in-ms-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring Microsoft SQL Express 2005</title>
		<link>http://dev.kratik.net/index.php/2008/10/30/configuring-microsoft-sql-express-2005/</link>
		<comments>http://dev.kratik.net/index.php/2008/10/30/configuring-microsoft-sql-express-2005/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 04:13:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/?p=454</guid>
		<description><![CDATA[<p>Microsoft SQL Express 2005 provides enterprise class database performance for free. However it does have some limitations when compared to the full version of SQL Server. But these limitations are not likely to adversely affect most PaperCut NG users. These limitations include</p>


4GB limit on database sizes
Limited to only use 1 CPU
Limited to only use 1GB [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft SQL Express 2005 provides enterprise class database performance for free. However it does have some limitations when compared to the full version of SQL Server. But these limitations are not likely to adversely affect most PaperCut NG users. These limitations include</p>
<div>
<ul type="disc">
<li>4GB limit on database sizes</li>
<li>Limited to only use 1 CPU</li>
<li>Limited to only use 1GB of RAM</li>
</ul>
</div>
<p> </p>
<p>This section described how to configure Microsoft SQL Express edition for use with PaperCut NG. It is assumed that SQL Server Express is already installed with the default configuration.</p>
<p>Once this configuration is complete, the database can be used with PaperCut NG by following the instructions in <a title="Upsizing to an External RDBMS" href="http://www.papercut.com/products/ng/manual/ch-ext-db-upsizing.html">the section called “Upsizing to an External RDBMS”</a>.</p>
<div class="sect2" lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="id506842"></a>Enable TCP/IP connections</h3>
</div>
</div>
</div>
<p>PaperCut NG uses TCP/IP to connect to the SQL Server database, but SQL Server Express does not enable TCP support by default. To enable TCP/IP:</p>
<div class="orderedlist">
<ol type="1">
<li>On the machine with SQL Express installed, open the <span class="guilabel">SQL Server Configuration Manager</span>.</li>
<li>Expand the <span class="guilabel">SQL Server 2005 Network Configuration</span> node on the left.</li>
<li>Select the <span class="guilabel">Protocols for SQLEXPRESS</span> node on the left.</li>
<li>Right-click the TCP/IP item on the right and select <span class="guilabel">Properties</span>.</li>
<li>On the <span class="guilabel">General</span> tab, change <span class="guilabel">Enabled</span> to Yes.</li>
<li>On the <span class="guilabel">IP Addresses</span> tab, under the <span class="guilabel">IPAll</span> node clear the <span class="guilabel">TCP Dynamic Ports</span> field. Also enter the port to listen on in the <span class="guilabel">TCP Port</span> field. For example, 1450. Remember this port, because it needs to be used in the PaperCut NG connection string.</li>
<li>On the <span class="guibutton">OK</span> button to save the changes.</li>
<li>Restart the Microsoft SQL Server Express service using either the standard service control panel or the SQL Express tools.</li>
</ol>
</div>
<p> </p></div>
<div class="sect2" lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="id506956"></a>Enable SQL Server authentication</h3>
</div>
</div>
</div>
<p>PaperCut NG requires SQL Server authentication to be enabled on the instance of SQL Express. To do this:</p>
<div class="orderedlist">
<ol type="1">
<li>On the machine with SQL Express installed, open the <span class="guilabel">SQL Server Management Studio Express</span> tool.</li>
<li>Right-click the instance of SQL Express to configure, and select <span class="guilabel">Properties</span>.</li>
<li>Select the <span class="guilabel">Security</span> section on the left.</li>
<li>Change the <span class="guilabel">Server Authentication</span> to <span class="guilabel">SQL Server and Windows Authentication mode</span>.</li>
<li>Restart the Microsoft SQL Server Express service using either the standard service control panel or the SQL Express tools.</li>
</ol>
</div>
<p> </p></div>
<div class="sect2" lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="id503984"></a>Create Database User</h3>
</div>
</div>
</div>
<p>PaperCut NG requires a user to connect to the database. To create this user:</p>
<div class="orderedlist">
<ol type="1">
<li>On the machine with SQL Express installed, open the <span class="guilabel">SQL Server Management Studio Express</span> tool.</li>
<li>Right-click the <span class="guilabel">Security-&gt;Logins</span> node, and select <span class="guilabel">New Login &#8230;</span>.</li>
<li>Enter the username (e.g. papercut).</li>
<li>Change the <span class="guilabel">Server Authentication</span> to <span class="guilabel">SQL Server and Windows Authentication mode</span>.</li>
<li>Enter the user&#8217;s password.</li>
<li>Disable password expiration.</li>
<li>On the <span class="guibutton">OK</span> button to create the user.</li>
<li>After creating the PaperCut NG database assign this user <code class="literal">db_owner</code> permissions on the database, so that it can create the required database tables.</li>
<li>To initialize the database, follow the instruction in <a title="Upsizing to an External RDBMS" href="http://www.papercut.com/products/ng/manual/ch-ext-db-upsizing.html">the section called “Upsizing to an External RDBMS”</a>. ref: http://www.papercut.com/products/ng/manual/ch-ext-db-sqlexpress.html
<p>ref: http://www.aspdotnetcodes.com/ Enable_Remote_Connections_SQLServerExpress.aspx</li>
</ol>
</div>
<p> </p></div>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2008/10/30/configuring-microsoft-sql-express-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL SERVER TIP</title>
		<link>http://dev.kratik.net/index.php/2007/11/29/sql-server-tip/</link>
		<comments>http://dev.kratik.net/index.php/2007/11/29/sql-server-tip/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 03:28:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/2007/11/29/sql-server-tip/</guid>
		<description><![CDATA[<p>http://www.sql-server-performance.com/</p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sql-server-performance.com/">http://www.sql-server-performance.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2007/11/29/sql-server-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>store procedure call store procedure</title>
		<link>http://dev.kratik.net/index.php/2007/11/21/store-procedure-call-store-procedure/</link>
		<comments>http://dev.kratik.net/index.php/2007/11/21/store-procedure-call-store-procedure/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 10:24:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/2007/11/21/store-procedure-call-store-procedure/</guid>
		<description><![CDATA[<p>&#60;script type=&#8221;text/javascript&#8221;&#62;&#60;!&#8211;
google_ad_client = &#8220;pub-2910472071369479&#8243;;
//728&#215;90, created 11/20/07
google_ad_slot = &#8220;7313632958&#8243;;
google_ad_width = 728;
google_ad_height = 90;
//&#8211;&#62;&#60;/script&#62;
&#60;script type=&#8221;text/javascript&#8221;
src=&#8221;http://pagead2.googlesyndication.com/pagead/show_ads.js&#8220;&#62;
&#60;/script&#62;
</p>
<p>src=&#8221;http://pagead2.googlesyndication.com/pagead/show_ads.js&#8221; mce_src=&#8221;http://pagead2.googlesyndication.com/pagead/show_ads.js&#8221;&#62;</p>
<p>set nocount on
declare @sql nvarchar(2000)
declare @comp_code nvarchar(255), @pin nvarchar(255), @LoanType nvarchar(255), @datefrom nvarchar(255)
declare @temp_id int, @n int
declare @docNo nvarchar(20)</p>
<p>create table #temp
(
 _id int IDENTITY,
 Company nvarchar(255),
 PIN nvarchar(255),
 LoanType nvarchar(255),
 df nvarchar(255)
)</p>
<p>insert into #temp
select Company, PIN, LoanType, convert(varchar,convert(datetime, DateFrom, 103),112) as df
from sheet1 where LoanType in (&#8217;01&#8242;,&#8217;02&#8242;,&#8217;03&#8242;,&#8217;04&#8242;,&#8217;05&#8242;) [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight:normal;font-size:9pt;color:#004200;font-style:normal;font-family:arial;">&lt;script type=&#8221;text/javascript&#8221;&gt;&lt;!&#8211;<br />
google_ad_client = &#8220;pub-2910472071369479&#8243;;<br />
//728&#215;90, created 11/20/07<br />
google_ad_slot = &#8220;7313632958&#8243;;<br />
google_ad_width = 728;<br />
google_ad_height = 90;<br />
//&#8211;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;<br />
src=&#8221;<a href="http://pagead2.googlesyndication.com/pagead/show_ads.js">http://pagead2.googlesyndication.com/pagead/show_ads.js</a>&#8220;&gt;<br />
&lt;/script&gt;<br />
</span></p>
<p>src=&#8221;http://pagead2.googlesyndication.com/pagead/show_ads.js&#8221; mce_src=&#8221;http://pagead2.googlesyndication.com/pagead/show_ads.js&#8221;&gt;</p>
<p>set nocount on<br />
declare @sql nvarchar(2000)<br />
declare @comp_code nvarchar(255), @pin nvarchar(255), @LoanType nvarchar(255), @datefrom nvarchar(255)<br />
declare @temp_id int, @n int<br />
declare @docNo nvarchar(20)</p>
<p>create table #temp<br />
(<br />
 _id int IDENTITY,<br />
 Company nvarchar(255),<br />
 PIN nvarchar(255),<br />
 LoanType nvarchar(255),<br />
 df nvarchar(255)<br />
)</p>
<p>insert into #temp<br />
select Company, PIN, LoanType, convert(varchar,convert(datetime, DateFrom, 103),112) as df<br />
from sheet1 where LoanType in (&#8217;01&#8242;,&#8217;02&#8242;,&#8217;03&#8242;,&#8217;04&#8242;,&#8217;05&#8242;) and convert(datetime, DateTo, 103) &gt;= getdate()<br />
order by pin</p>
<p>set @n = 0</p>
<p>&#8211; loop &#8211;<br />
declare cur cursor for<br />
select _id from #temp<br />
open cur<br />
fetch next from cur into @temp_id  <br />
 while @@fetch_status=0<br />
 begin <br />
  set @n = @n + 1<br />
 <br />
  exec get_running_number @n, @docNo out<br />
 <br />
  select @comp_code=Company, @pin=PIN, @LoanType=LoanType, @datefrom=df from #temp where <a href="mailto:_id=@temp_id">_id=@temp_id</a><br />
 <br />
  set @sql = &#8216;insert into welfare.WF2_TXN_CREMATION (Comp_Code,Pin,Doc_Date,Relat_Pers_Type, Doc_No) values &#8216;<br />
  set @sql = @sql + &#8216;(&#8221;&#8217; + @comp_code + &#8221;&#8217;,&#8221;&#8217;+ @pin + &#8221;&#8217;,&#8221;&#8217; + @datefrom + &#8221;&#8217;,&#8221;&#8217;<br />
+ @LoanType + &#8221;&#8217;,&#8221;&#8217; + @docNo + &#8221;&#8217;)&#8217;<br />
  print (@sql)<br />
 <br />
  fetch next from cur into @temp_id <br />
 end<br />
<br />
 print &#8216;&#8211; total record: &#8216; + cast(@n as varchar)</p>
<p>close cur<br />
deallocate cur</p>
<p>&#8211; drop table &#8211;<br />
drop table #temp    </p>
<p>set nocount off</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2007/11/21/store-procedure-call-store-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>store procedure for return value string format</title>
		<link>http://dev.kratik.net/index.php/2007/11/21/store-procedure-for-return-value-string-format/</link>
		<comments>http://dev.kratik.net/index.php/2007/11/21/store-procedure-for-return-value-string-format/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 10:22:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/2007/11/21/store-procedure-for-return-value-string-format/</guid>
		<description><![CDATA[<p>CREATE PROCEDURE get_running_number
@id int,
@docNO varchar(20)  out
AS
begin
 declare @_id nvarchar(20)
 declare @i int
 set @_id = cast(@id as nvarchar)
 set @i = len(@_id)
 while (@i&#60;5)
 begin
  set @_id = &#8216;0&#8242; + @_id
  set @i = @i +1
 end
 set @_id = &#8216;WF0711&#8242; + @_id
      select @docNO =  @_id
end
GO</p>
]]></description>
			<content:encoded><![CDATA[<p>CREATE PROCEDURE get_running_number<br />
@id int,<br />
@docNO varchar(20)  out<br />
AS<br />
begin<br />
 declare @_id nvarchar(20)<br />
 declare @i int<br />
 set @_id = cast(@id as nvarchar)<br />
 set @i = len(@_id)<br />
 while (@i&lt;5)<br />
 begin<br />
  set @_id = &#8216;0&#8242; + @_id<br />
  set @i = @i +1<br />
 end<br />
 set @_id = &#8216;WF0711&#8242; + @_id<br />
      select @docNO =  @_id<br />
end<br />
GO</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2007/11/21/store-procedure-for-return-value-string-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sql datetime format</title>
		<link>http://dev.kratik.net/index.php/2007/11/20/sql-datetime-format/</link>
		<comments>http://dev.kratik.net/index.php/2007/11/20/sql-datetime-format/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 12:22:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/2007/11/20/sql-datetime-format/</guid>
		<description><![CDATA[<p>select
Company, PIN, Type, convert(varchar,convert(datetime, DateFrom, 103),112) as df
from sheet1
where Type in (&#8217;01&#8242;,&#8217;02&#8242;,&#8217;03&#8242;,&#8217;04&#8242;,&#8217;05&#8242;)</p>
]]></description>
			<content:encoded><![CDATA[<p>select<br />
Company, PIN, Type, convert(varchar,convert(datetime, DateFrom, 103),112) as df<br />
from sheet1<br />
where Type in (&#8217;01&#8242;,&#8217;02&#8242;,&#8217;03&#8242;,&#8217;04&#8242;,&#8217;05&#8242;)</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2007/11/20/sql-datetime-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSSQL 2000 Log file full</title>
		<link>http://dev.kratik.net/index.php/2007/11/09/mssql-2000-log-file-full/</link>
		<comments>http://dev.kratik.net/index.php/2007/11/09/mssql-2000-log-file-full/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 13:27:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/2007/11/09/mssql-2000-log-file-full/</guid>
		<description><![CDATA[<p>- backup log DATABSENAME with no_log</p>
<p>- shink  thik true on top checkbox and set value = 20%</p>
]]></description>
			<content:encoded><![CDATA[<p>- backup log DATABSENAME with no_log</p>
<p>- shink  thik true on top checkbox and set value = 20%</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2007/11/09/mssql-2000-log-file-full/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paging with Store procedure</title>
		<link>http://dev.kratik.net/index.php/2007/10/26/paging-with-store-procedure/</link>
		<comments>http://dev.kratik.net/index.php/2007/10/26/paging-with-store-procedure/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 08:17:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/2007/10/26/paging-with-store-procedure/</guid>
		<description><![CDATA[<p>set nocount on</p>
<p>declare @FirstRec int, @LastRec int
declare @Page int, @RecsPerPage int
set @Page = 4
set @RecsPerPage = 3</p>
<p>CREATE TABLE #TempTable1
(
 ID int IDENTITY,
 Comp_Code varchar(3),
 Org_id varchar(8)
)</p>
<p>INSERT INTO #TempTable1 (Comp_Code, Org_id)
SELECT Comp_Code, Org_id FROM WF_MST_VENDOR</p>
<p>SELECT @FirstRec = (@Page &#8211; 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)</p>
<p>SELECT *,MoreRecords = ( SELECT COUNT(*)  FROM #TempTable1 TI  WHERE TI.ID [...]]]></description>
			<content:encoded><![CDATA[<p>set nocount on</p>
<p>declare @FirstRec int, @LastRec int<br />
declare @Page int, @RecsPerPage int<br />
set @Page = 4<br />
set @RecsPerPage = 3</p>
<p>CREATE TABLE #TempTable1<br />
(<br />
 ID int IDENTITY,<br />
 Comp_Code varchar(3),<br />
 Org_id varchar(8)<br />
)</p>
<p>INSERT INTO #TempTable1 (Comp_Code, Org_id)<br />
SELECT Comp_Code, Org_id FROM WF_MST_VENDOR</p>
<p>SELECT @FirstRec = (@Page &#8211; 1) * @RecsPerPage<br />
SELECT @LastRec = (@Page * @RecsPerPage + 1)</p>
<p>SELECT *,MoreRecords = ( SELECT COUNT(*)  FROM #TempTable1 TI  WHERE TI.ID &gt;= @LastRec)<br />
FROM #TempTable1<br />
WHERE ID &gt; @FirstRec AND ID &lt; @LastRec</p>
<p>drop TABLE #TempTable1</p>
<p>set nocount off</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2007/10/26/paging-with-store-procedure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DataSet Paging with Store procedure</title>
		<link>http://dev.kratik.net/index.php/2007/10/22/dataset-paging-with-store-procedure/</link>
		<comments>http://dev.kratik.net/index.php/2007/10/22/dataset-paging-with-store-procedure/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 12:58:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DATABASE]]></category>

		<guid isPermaLink="false">http://dev1.wordpress.com/2007/10/22/dataset-paging-with-store-procedure/</guid>
		<description><![CDATA[CREATE PROCEDURE sp_PagedItems
 (
  @Page int,
  @RecsPerPage int
 )
AS
-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON

--Create a temporary table
CREATE TABLE #TempItems
(
 ID int IDENTITY,
 Name varchar(50),
 Price currency
)

-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (Name, Price)
SELECT Name,Price FROM tblItem ORDER BY Price
-- [...]]]></description>
			<content:encoded><![CDATA[<pre>CREATE PROCEDURE sp_PagedItems
 (
  @Page int,
  @RecsPerPage int
 )
AS</pre>
<pre>-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON</pre>
<pre>
--Create a temporary table
CREATE TABLE #TempItems
(
 ID int IDENTITY,
 Name varchar(50),
 Price currency
)</pre>
<pre>
-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (Name, Price)
SELECT Name,Price FROM tblItem ORDER BY Price</pre>
<pre>-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)</pre>
<pre>-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
       MoreRecords =
 (
  SELECT COUNT(*)
  FROM #TempItems TI
  WHERE TI.ID &gt;= @LastRec
 )
FROM #TempItems
WHERE ID &gt; @FirstRec AND ID &lt; @LastRec</pre>
<pre>
-- Turn NOCOUNT back OFF
SET NOCOUNT OFF</pre>
<pre> </pre>
<pre>ref: <a href="http://www.aspfaqs.com/webtech/062899-1.shtml">http://www.aspfaqs.com/webtech/062899-1.shtml</a></pre>
<pre>ref: <a href="http://technet.microsoft.com/en-us/library/ms174998.aspx">http://technet.microsoft.com/en-us/library/ms174998.aspx</a></pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.kratik.net/index.php/2007/10/22/dataset-paging-with-store-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
