<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Database Coding Standards and Guidelines &#8211; Part 2</title>
	<atom:link href="http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sun, 12 Feb 2012 09:22:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-112447</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Fri, 21 Jan 2011 11:01:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-112447</guid>
		<description><![CDATA[No you need to use unambigious date format
Refer this for  more infromations
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx]]></description>
		<content:encoded><![CDATA[<p>No you need to use unambigious date format<br />
Refer this for  more infromations<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mathi</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-111941</link>
		<dc:creator><![CDATA[mathi]]></dc:creator>
		<pubDate>Wed, 19 Jan 2011 04:46:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-111941</guid>
		<description><![CDATA[try to this 

SELECT MAX(Price),name 
FROM
(
SELECT TOP 2 Price
FROM Products
ORDER BY Price DESC
)ProductDerivedTable]]></description>
		<content:encoded><![CDATA[<p>try to this </p>
<p>SELECT MAX(Price),name<br />
FROM<br />
(<br />
SELECT TOP 2 Price<br />
FROM Products<br />
ORDER BY Price DESC<br />
)ProductDerivedTable</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mathi</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-111940</link>
		<dc:creator><![CDATA[mathi]]></dc:creator>
		<pubDate>Wed, 19 Jan 2011 04:44:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-111940</guid>
		<description><![CDATA[inpput date format is   &#039;MM\DD\YYYY&#039;]]></description>
		<content:encoded><![CDATA[<p>inpput date format is   &#8216;MM\DD\YYYY&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maria</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-71560</link>
		<dc:creator><![CDATA[Maria]]></dc:creator>
		<pubDate>Wed, 19 May 2010 07:49:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-71560</guid>
		<description><![CDATA[Hello sir,

Is there any function to replace &quot;space&quot; in a table with null or some other values.
Like I need to select a column(column1) which is having &quot;space&quot; in it and i have to replace that column(column1) with another column(column2) if any null or space is there in the 1st column(column1).
I don&#039;t want to use &quot;if&quot; and &quot;case&quot;, without this is there any other way.
Kindly suggest me.

Thanks and regards,
Maria]]></description>
		<content:encoded><![CDATA[<p>Hello sir,</p>
<p>Is there any function to replace &#8220;space&#8221; in a table with null or some other values.<br />
Like I need to select a column(column1) which is having &#8220;space&#8221; in it and i have to replace that column(column1) with another column(column2) if any null or space is there in the 1st column(column1).<br />
I don&#8217;t want to use &#8220;if&#8221; and &#8220;case&#8221;, without this is there any other way.<br />
Kindly suggest me.</p>
<p>Thanks and regards,<br />
Maria</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Akhila</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-60774</link>
		<dc:creator><![CDATA[Akhila]]></dc:creator>
		<pubDate>Sat, 06 Feb 2010 04:37:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-60774</guid>
		<description><![CDATA[Just a suggestion.

In the reference point number 6, we are missing the alias name for the derived table

It should have been something like

SELECT MAX(Price)
    FROM
    (
    SELECT TOP 2 Price
        FROM Products
        ORDER BY Price DESC
    )ProductDerivedTable]]></description>
		<content:encoded><![CDATA[<p>Just a suggestion.</p>
<p>In the reference point number 6, we are missing the alias name for the derived table</p>
<p>It should have been something like</p>
<p>SELECT MAX(Price)<br />
    FROM<br />
    (<br />
    SELECT TOP 2 Price<br />
        FROM Products<br />
        ORDER BY Price DESC<br />
    )ProductDerivedTable</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashish</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-57999</link>
		<dc:creator><![CDATA[Ashish]]></dc:creator>
		<pubDate>Mon, 30 Nov 2009 06:17:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-57999</guid>
		<description><![CDATA[why not to use the identitycol or rowguidcol. 

its urgent .
Thanks and Regards

Ashsih Gupta]]></description>
		<content:encoded><![CDATA[<p>why not to use the identitycol or rowguidcol. </p>
<p>its urgent .<br />
Thanks and Regards</p>
<p>Ashsih Gupta</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Omprakash yadav</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-46018</link>
		<dc:creator><![CDATA[Omprakash yadav]]></dc:creator>
		<pubDate>Tue, 27 Jan 2009 07:48:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-46018</guid>
		<description><![CDATA[Sir, I m facing problem while accessing the date column inside the while loop . can u give the alternate solution.. 
     
WHILE (SELECT DISTINCT DATE FROM HOLIDAYS H WHERE DATE &gt;= @FROM_DATE AND DATE &lt;= @TO_DATE) IS NOT NULL
	BEGIN
		SET @H_DAY = @H_DAY + DATEPART(d,H.DATE)
	END

Regards,]]></description>
		<content:encoded><![CDATA[<p>Sir, I m facing problem while accessing the date column inside the while loop . can u give the alternate solution.. </p>
<p>WHILE (SELECT DISTINCT DATE FROM HOLIDAYS H WHERE DATE &gt;= @FROM_DATE AND DATE &lt;= @TO_DATE) IS NOT NULL<br />
	BEGIN<br />
		SET @H_DAY = @H_DAY + DATEPART(d,H.DATE)<br />
	END</p>
<p>Regards,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeevan</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-39979</link>
		<dc:creator><![CDATA[Jeevan]]></dc:creator>
		<pubDate>Wed, 09 Jul 2008 17:23:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-39979</guid>
		<description><![CDATA[Dear Mr. sir thanks a lot.....]]></description>
		<content:encoded><![CDATA[<p>Dear Mr. sir thanks a lot&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kent</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-37940</link>
		<dc:creator><![CDATA[Kent]]></dc:creator>
		<pubDate>Tue, 13 May 2008 16:25:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-37940</guid>
		<description><![CDATA[You didn&#039;t mention much on VIEW nomenclature.

I use views to represent data for consumption by Application software. The Application user (say &quot;AppUser&quot;) is NOT the dbo. So, access is only granted to views and columns allowed by the dbo. This is a powerful layer of abstraction.

Also, for .Net developers using LINQ. Using a plural on entity names is nice. A LIST has a single row object of Customer. I went with singular entity names for many years and have since changed my thinking.]]></description>
		<content:encoded><![CDATA[<p>You didn&#8217;t mention much on VIEW nomenclature.</p>
<p>I use views to represent data for consumption by Application software. The Application user (say &#8220;AppUser&#8221;) is NOT the dbo. So, access is only granted to views and columns allowed by the dbo. This is a powerful layer of abstraction.</p>
<p>Also, for .Net developers using LINQ. Using a plural on entity names is nice. A LIST has a single row object of Customer. I went with singular entity names for many years and have since changed my thinking.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: umakar</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-37457</link>
		<dc:creator><![CDATA[umakar]]></dc:creator>
		<pubDate>Sat, 10 May 2008 07:04:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-37457</guid>
		<description><![CDATA[hello sir 
plz send projects on ms  sql  server 2000&amp;2005 with coding
iam struggling hard to get code on stored proc
thank u sir]]></description>
		<content:encoded><![CDATA[<p>hello sir<br />
plz send projects on ms  sql  server 2000&amp;2005 with coding<br />
iam struggling hard to get code on stored proc<br />
thank u sir</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Miller</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-34948</link>
		<dc:creator><![CDATA[Chris Miller]]></dc:creator>
		<pubDate>Wed, 09 Apr 2008 17:48:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-34948</guid>
		<description><![CDATA[Hi Pinal,

Why is using &quot;&quot; as a  comparison operator less efficient than using a set operator?

thanks,
Chris]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Why is using &#8220;&#8221; as a  comparison operator less efficient than using a set operator?</p>
<p>thanks,<br />
Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-19090</link>
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Mon, 12 Nov 2007 14:49:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-19090</guid>
		<description><![CDATA[Doug,

Scott Mitchell has a good article on paging large result sets: http://www.4guysfromrolla.com/webtech/042606-1.shtml

If you&#039;re using SQL Server 2000, also check out this post: http://forums.asp.net/t/1050460.aspx]]></description>
		<content:encoded><![CDATA[<p>Doug,</p>
<p>Scott Mitchell has a good article on paging large result sets: <a href="http://www.4guysfromrolla.com/webtech/042606-1.shtml" rel="nofollow">http://www.4guysfromrolla.com/webtech/042606-1.shtml</a></p>
<p>If you&#8217;re using SQL Server 2000, also check out this post: <a href="http://forums.asp.net/t/1050460.aspx" rel="nofollow">http://forums.asp.net/t/1050460.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug McDonald</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-18062</link>
		<dc:creator><![CDATA[Doug McDonald]]></dc:creator>
		<pubDate>Thu, 08 Nov 2007 17:25:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-18062</guid>
		<description><![CDATA[Hi There, I wondered if there is a handy way within SQL server to select say, the rows numbered 500-1000.

The basis for this request is that I have a small website that was working fine for displaying results, but now the result set is soo huge that pages are performing badly (on occasion timing out).

What I would like to do it select say, the top 500 rows for page one, second 500 rows for page 2 etc etc.

Whilst I am aware of offset commands in things like MySQL, I have not come accross anything like this in SQL Server. 

Does anyone know of any nice ways to do this?

Thanks in advance, Doug]]></description>
		<content:encoded><![CDATA[<p>Hi There, I wondered if there is a handy way within SQL server to select say, the rows numbered 500-1000.</p>
<p>The basis for this request is that I have a small website that was working fine for displaying results, but now the result set is soo huge that pages are performing badly (on occasion timing out).</p>
<p>What I would like to do it select say, the top 500 rows for page one, second 500 rows for page 2 etc etc.</p>
<p>Whilst I am aware of offset commands in things like MySQL, I have not come accross anything like this in SQL Server. </p>
<p>Does anyone know of any nice ways to do this?</p>
<p>Thanks in advance, Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ardian</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-14848</link>
		<dc:creator><![CDATA[Ardian]]></dc:creator>
		<pubDate>Fri, 05 Oct 2007 22:01:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-14848</guid>
		<description><![CDATA[thank you for this tutorial, it&#039;s very usefull for me]]></description>
		<content:encoded><![CDATA[<p>thank you for this tutorial, it&#8217;s very usefull for me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anil</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-13540</link>
		<dc:creator><![CDATA[anil]]></dc:creator>
		<pubDate>Fri, 21 Sep 2007 19:32:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-13540</guid>
		<description><![CDATA[my table structure was like 
  
 cond 1:  row1 datetime1 &lt;= datetime2 
 
 cond 2:  row2 datedtime1&lt;= row1 datetime2

   here i need to find leasure time using row1 datetime2 - row 2 datetime1
  
	row1  2007-09-20 15:30:29.000	2007-09-20 16:35:29.130
	row2  2007-09-20 15:31:29.000	2007-09-20 16:35:34.130
	row3  2007-09-20 15:32:34.000	2007-09-20 16:35:49.130
	row4  2007-09-20 15:33:49.000	2007-09-20 16:35:54.130
	row5  2007-09-20 15:34:34.000	2007-09-20 17:06:34.130
	row6  2007-09-20 15:35:34.000	2007-09-20 17:06:39.130
	row7  2007-09-20 15:36:34.000	2007-09-20 17:36:34.130
	row8  2007-09-20 15:37:34.000	2007-09-20 17:36:39.130
	row9  2007-09-20 15:38:34.000	2007-09-20 18:06:34.130
	row10 2007-09-20 15:39:34.000	2007-09-20 18:06:39.130
	row11 2007-09-20 15:40:34.000	2007-09-20 18:35:49.130
	row12 2007-09-20 15:41:49.000	2007-09-20 18:35:54.130

Please give me select query for this]]></description>
		<content:encoded><![CDATA[<p>my table structure was like </p>
<p> cond 1:  row1 datetime1 &lt;= datetime2 </p>
<p> cond 2:  row2 datedtime1&lt;= row1 datetime2</p>
<p>   here i need to find leasure time using row1 datetime2 &#8211; row 2 datetime1</p>
<p>	row1  2007-09-20 15:30:29.000	2007-09-20 16:35:29.130<br />
	row2  2007-09-20 15:31:29.000	2007-09-20 16:35:34.130<br />
	row3  2007-09-20 15:32:34.000	2007-09-20 16:35:49.130<br />
	row4  2007-09-20 15:33:49.000	2007-09-20 16:35:54.130<br />
	row5  2007-09-20 15:34:34.000	2007-09-20 17:06:34.130<br />
	row6  2007-09-20 15:35:34.000	2007-09-20 17:06:39.130<br />
	row7  2007-09-20 15:36:34.000	2007-09-20 17:36:34.130<br />
	row8  2007-09-20 15:37:34.000	2007-09-20 17:36:39.130<br />
	row9  2007-09-20 15:38:34.000	2007-09-20 18:06:34.130<br />
	row10 2007-09-20 15:39:34.000	2007-09-20 18:06:39.130<br />
	row11 2007-09-20 15:40:34.000	2007-09-20 18:35:49.130<br />
	row12 2007-09-20 15:41:49.000	2007-09-20 18:35:54.130</p>
<p>Please give me select query for this</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-4626</link>
		<dc:creator><![CDATA[Ivan]]></dc:creator>
		<pubDate>Wed, 11 Jul 2007 13:41:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-4626</guid>
		<description><![CDATA[Very good site and great standards and guidelines.  

My question is regarding cursors.  Everywhere I read do not use cursors instead use while loops.  I did a test with 2.6 million records and the cursor took 4 minutes and the while loop took 12 minutes.  

I am using SQL Server 2005 

Create PROCEDURE [Company].[uspVendorKeyIDGets_IMC_whileloop]
	@Vendor VARCHAR(50),	
	--@KeyIDServer VARCHAR(50),
	@KeyIDBlockSize INT = 100

-- exec [Company].[uspVendorKeyIDGets_IMC] &#039;iusacredit&#039;,100
WITH EXECUTE AS CALLER
AS
SET NOCOUNT ON

DECLARE @N INT, @Index INT, @Loop INT, @KeyID INT, @VendorFeedID INT
DECLARE @KeyIDList VARCHAR(8000)
DECLARE @StartTime DATETIME
DECLARE @iCustLoopControl INT

select @VendorFeedID=VendorFeedID FROM dbo.VendorFeed WHERE Name=@Vendor
IF @@ROWCOUNT  1 
BEGIN
	return
END

SET @N = 200 -- for testing
SET @Loop = @KeyIDBlockSize

SET @StartTime = GETDATE()
PRINT Convert(varchar(20),@StartTime) + &#039; StartTime&#039;

-- replace CURSOR with WHILE LOOP
SELECT     @iCustLoopControl = 1

-- retrieve the first row
SELECT		@Keyid = MIN(keyid) 
FROM		company.companykeyid with(nolock) 
WHERE		VendorFeedID = 40

-- start the main processing
WHILE @iCustLoopControl = 1
BEGIN
	SET @Index = 1
    SET @KeyIDList = CONVERT(VARCHAR(10), @KeyID)
	
	 -- start the nested loop for 100 records
	WHILE @Index  @Keyid

		SET @Index = @Index + 1	

		IF ISNULL(@KeyID,0) = 0
		BEGIN
			SET @iCustLoopControl = 0
			BREAK
		END          
	END
	SET @StartTime = GETDATE()
END

PRINT Convert(varchar(20),GETDATE()) + &#039; EndTime&#039;




CREATE PROCEDURE [Company].[uspVendorKeyIDGets_IMC_cursor]
	@Vendor VARCHAR(50),	
	--@KeyIDServer VARCHAR(50),
	@KeyIDBlockSize INT = 100

-- exec [Company].[uspVendorKeyIDGets_IMC_cursor] &#039;iusacredit&#039;,100
WITH EXECUTE AS CALLER
AS
SET NOCOUNT ON

DECLARE @N INT, @Index INT, @Loop INT, @KeyID INT, @VendorFeedID INT
DECLARE @KeyIDList VARCHAR(8000)
DECLARE @StartTime DATETIME
DECLARE @iCustLoopControl INT

select @VendorFeedID=VendorFeedID FROM dbo.VendorFeed WHERE Name=@Vendor
IF @@ROWCOUNT  1 
BEGIN
	return
END

SET @N = 200 -- for testing
SET @Loop = @KeyIDBlockSize

SET @StartTime = GETDATE()
PRINT Convert(varchar(20),@StartTime) + &#039; StartTime&#039;

    -- Make it forward_only static so that a temp company is made and used otherwise we get tripped up by other loaders
    DECLARE KeyID_Cursor CURSOR FORWARD_ONLY STATIC --FAST_FORWARD
	FOR SELECT DISTINCT KeyID FROM Company.CompanyKeyID with(nolock) WHERE VendorFeedID = 40	;

OPEN KeyID_Cursor
FETCH NEXT FROM KeyID_Cursor INTO @KeyID
WHILE @@FETCH_STATUS = 0
BEGIN
	SET @Index = 1
	SET @KeyIDList = CONVERT(VARCHAR(10), @KeyID)
	WHILE @Index ]]></description>
		<content:encoded><![CDATA[<p>Very good site and great standards and guidelines.  </p>
<p>My question is regarding cursors.  Everywhere I read do not use cursors instead use while loops.  I did a test with 2.6 million records and the cursor took 4 minutes and the while loop took 12 minutes.  </p>
<p>I am using SQL Server 2005 </p>
<p>Create PROCEDURE [Company].[uspVendorKeyIDGets_IMC_whileloop]<br />
	@Vendor VARCHAR(50),<br />
	&#8211;@KeyIDServer VARCHAR(50),<br />
	@KeyIDBlockSize INT = 100</p>
<p>&#8211; exec [Company].[uspVendorKeyIDGets_IMC] &#8216;iusacredit&#8217;,100<br />
WITH EXECUTE AS CALLER<br />
AS<br />
SET NOCOUNT ON</p>
<p>DECLARE @N INT, @Index INT, @Loop INT, @KeyID INT, @VendorFeedID INT<br />
DECLARE @KeyIDList VARCHAR(8000)<br />
DECLARE @StartTime DATETIME<br />
DECLARE @iCustLoopControl INT</p>
<p>select @VendorFeedID=VendorFeedID FROM dbo.VendorFeed WHERE Name=@Vendor<br />
IF @@ROWCOUNT  1<br />
BEGIN<br />
	return<br />
END</p>
<p>SET @N = 200 &#8212; for testing<br />
SET @Loop = @KeyIDBlockSize</p>
<p>SET @StartTime = GETDATE()<br />
PRINT Convert(varchar(20),@StartTime) + &#8216; StartTime&#8217;</p>
<p>&#8211; replace CURSOR with WHILE LOOP<br />
SELECT     @iCustLoopControl = 1</p>
<p>&#8211; retrieve the first row<br />
SELECT		@Keyid = MIN(keyid)<br />
FROM		company.companykeyid with(nolock)<br />
WHERE		VendorFeedID = 40</p>
<p>&#8211; start the main processing<br />
WHILE @iCustLoopControl = 1<br />
BEGIN<br />
	SET @Index = 1<br />
    SET @KeyIDList = CONVERT(VARCHAR(10), @KeyID)</p>
<p>	 &#8212; start the nested loop for 100 records<br />
	WHILE @Index  @Keyid</p>
<p>		SET @Index = @Index + 1	</p>
<p>		IF ISNULL(@KeyID,0) = 0<br />
		BEGIN<br />
			SET @iCustLoopControl = 0<br />
			BREAK<br />
		END<br />
	END<br />
	SET @StartTime = GETDATE()<br />
END</p>
<p>PRINT Convert(varchar(20),GETDATE()) + &#8216; EndTime&#8217;</p>
<p>CREATE PROCEDURE [Company].[uspVendorKeyIDGets_IMC_cursor]<br />
	@Vendor VARCHAR(50),<br />
	&#8211;@KeyIDServer VARCHAR(50),<br />
	@KeyIDBlockSize INT = 100</p>
<p>&#8211; exec [Company].[uspVendorKeyIDGets_IMC_cursor] &#8216;iusacredit&#8217;,100<br />
WITH EXECUTE AS CALLER<br />
AS<br />
SET NOCOUNT ON</p>
<p>DECLARE @N INT, @Index INT, @Loop INT, @KeyID INT, @VendorFeedID INT<br />
DECLARE @KeyIDList VARCHAR(8000)<br />
DECLARE @StartTime DATETIME<br />
DECLARE @iCustLoopControl INT</p>
<p>select @VendorFeedID=VendorFeedID FROM dbo.VendorFeed WHERE Name=@Vendor<br />
IF @@ROWCOUNT  1<br />
BEGIN<br />
	return<br />
END</p>
<p>SET @N = 200 &#8212; for testing<br />
SET @Loop = @KeyIDBlockSize</p>
<p>SET @StartTime = GETDATE()<br />
PRINT Convert(varchar(20),@StartTime) + &#8216; StartTime&#8217;</p>
<p>    &#8212; Make it forward_only static so that a temp company is made and used otherwise we get tripped up by other loaders<br />
    DECLARE KeyID_Cursor CURSOR FORWARD_ONLY STATIC &#8211;FAST_FORWARD<br />
	FOR SELECT DISTINCT KeyID FROM Company.CompanyKeyID with(nolock) WHERE VendorFeedID = 40	;</p>
<p>OPEN KeyID_Cursor<br />
FETCH NEXT FROM KeyID_Cursor INTO @KeyID<br />
WHILE @@FETCH_STATUS = 0<br />
BEGIN<br />
	SET @Index = 1<br />
	SET @KeyIDList = CONVERT(VARCHAR(10), @KeyID)<br />
	WHILE @Index</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Salam</title>
		<link>http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-4362</link>
		<dc:creator><![CDATA[Salam]]></dc:creator>
		<pubDate>Thu, 05 Jul 2007 14:22:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/06/05/sql-server-database-coding-standards-and-guidelines-part-2/#comment-4362</guid>
		<description><![CDATA[hello sir

 Thank you sir.. it is very usefull .. it helps me very much ..
 keep updating .. once again thanks

Salam]]></description>
		<content:encoded><![CDATA[<p>hello sir</p>
<p> Thank you sir.. it is very usefull .. it helps me very much ..<br />
 keep updating .. once again thanks</p>
<p>Salam</p>
]]></content:encoded>
	</item>
</channel>
</rss>

