<?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/"
		>
<channel>
	<title>Comments on: How to Convert Cursor into While Loop In Sqlserver ?</title>
	<atom:link href="http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/</link>
	<description>&#62;&#62; Developer Blog</description>
	<lastBuildDate>Mon, 30 Jan 2012 08:47:08 -0800</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: links for 2011-01-17 &#171; Skmic&#8217;s Blog</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-11581</link>
		<dc:creator>links for 2011-01-17 &#171; Skmic&#8217;s Blog</dc:creator>
		<pubDate>Mon, 17 Jan 2011 12:02:19 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-11581</guid>
		<description>[...] Digicorp &#8211; How to Convert Cursor into While Loop In Sqlserver ? (tags: SQL) [...]</description>
		<content:encoded><![CDATA[<p>[...] Digicorp &#8211; How to Convert Cursor into While Loop In Sqlserver ? (tags: SQL) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ali</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-230</link>
		<dc:creator>Ali</dc:creator>
		<pubDate>Thu, 02 Jul 2009 07:32:04 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-230</guid>
		<description>Really u saved my time and efforts , thanks alot</description>
		<content:encoded><![CDATA[<p>Really u saved my time and efforts , thanks alot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-189</link>
		<dc:creator>Jack</dc:creator>
		<pubDate>Tue, 23 Jun 2009 10:51:22 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-189</guid>
		<description>Yes certainly a nice aproach..</description>
		<content:encoded><![CDATA[<p>Yes certainly a nice aproach..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kuldip</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-188</link>
		<dc:creator>Kuldip</dc:creator>
		<pubDate>Tue, 23 Jun 2009 10:48:11 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-188</guid>
		<description>it&#039;s nice thing it&#039;s working in some codition not in every condition it&#039;s work.
one thing is you need Primary key column in your temp table for this thing
you are not able do without primary key column, so if you want to work on varchar 
then it&#039;s not work.
If you remove from the #temp table then that good approch because it has confirm that 
no records will repeat.

another thing you are not able to do on the forgien key tables because it always 
have more than one entry in the table.</description>
		<content:encoded><![CDATA[<p>it&#8217;s nice thing it&#8217;s working in some codition not in every condition it&#8217;s work.<br />
one thing is you need Primary key column in your temp table for this thing<br />
you are not able do without primary key column, so if you want to work on varchar<br />
then it&#8217;s not work.<br />
If you remove from the #temp table then that good approch because it has confirm that<br />
no records will repeat.</p>
<p>another thing you are not able to do on the forgien key tables because it always<br />
have more than one entry in the table.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pranav Rajyaguru</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-187</link>
		<dc:creator>Pranav Rajyaguru</dc:creator>
		<pubDate>Tue, 23 Jun 2009 10:33:51 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-187</guid>
		<description>Nice article kuldip,

Thanks for sharing

I have just implement the same approach but my case is little different.
I don&#039;t want to delete records from temp table so I have used below approach. 

DECLARE @iNextCalID BIGINT, @iCurrCalID BIGINT

SET @iCurrCalID = 0;

WHILE(1 = 1)
BEGIN
	SELECT
	         @iNextCalID = MIN(CalendarID)
     	FROM
	         #tmpCalendar
	WHERE
		CalendarID &gt; @iCurrCalID;
		
					
	IF @iNextCalID is NULL		   
		BREAK;
				
	SET @iCurrCalID = @iNextCalID;
END

----------------------------------------------------

Here what I have done is,
Instead of deleting the record from temp table get MIN(Primary Key ID) where Primary Key ID is Grater Than (&gt;) current ID and assign it to Next ID.. 

If Next ID is NULL then BREAK the LOOP...

This approach is also good and replacable of CURSOR if you want to keep your TEMP table as it is...</description>
		<content:encoded><![CDATA[<p>Nice article kuldip,</p>
<p>Thanks for sharing</p>
<p>I have just implement the same approach but my case is little different.<br />
I don&#8217;t want to delete records from temp table so I have used below approach. </p>
<p>DECLARE @iNextCalID BIGINT, @iCurrCalID BIGINT</p>
<p>SET @iCurrCalID = 0;</p>
<p>WHILE(1 = 1)<br />
BEGIN<br />
	SELECT<br />
	         @iNextCalID = MIN(CalendarID)<br />
     	FROM<br />
	         #tmpCalendar<br />
	WHERE<br />
		CalendarID &gt; @iCurrCalID;</p>
<p>	IF @iNextCalID is NULL<br />
		BREAK;</p>
<p>	SET @iCurrCalID = @iNextCalID;<br />
END</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Here what I have done is,<br />
Instead of deleting the record from temp table get MIN(Primary Key ID) where Primary Key ID is Grater Than (&gt;) current ID and assign it to Next ID.. </p>
<p>If Next ID is NULL then BREAK the LOOP&#8230;</p>
<p>This approach is also good and replacable of CURSOR if you want to keep your TEMP table as it is&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-186</link>
		<dc:creator>Jack</dc:creator>
		<pubDate>Tue, 23 Jun 2009 10:23:21 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-186</guid>
		<description>Hey Kuldip this is really nice article...

Thanks for sharing information.

Regards
Jigar</description>
		<content:encoded><![CDATA[<p>Hey Kuldip this is really nice article&#8230;</p>
<p>Thanks for sharing information.</p>
<p>Regards<br />
Jigar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dipak Narsangani</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-182</link>
		<dc:creator>Dipak Narsangani</dc:creator>
		<pubDate>Tue, 23 Jun 2009 09:24:21 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-182</guid>
		<description>Really a good article.
Thanks for sharing the knowledge &amp; such a nice article.
Hope you will continue this in future as well.</description>
		<content:encoded><![CDATA[<p>Really a good article.<br />
Thanks for sharing the knowledge &amp; such a nice article.<br />
Hope you will continue this in future as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Virat</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-179</link>
		<dc:creator>Virat</dc:creator>
		<pubDate>Tue, 23 Jun 2009 08:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-179</guid>
		<description>Nice and helpful article.</description>
		<content:encoded><![CDATA[<p>Nice and helpful article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Virat</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-178</link>
		<dc:creator>Virat</dc:creator>
		<pubDate>Tue, 23 Jun 2009 08:35:42 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-178</guid>
		<description>Nice and practically needed functionality.</description>
		<content:encoded><![CDATA[<p>Nice and practically needed functionality.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikunj</title>
		<link>http://dev.digi-corp.com/2009/06/how-to-convert-cursor-into-while-loop-in-sqlserver/comment-page-1/#comment-174</link>
		<dc:creator>Nikunj</dc:creator>
		<pubDate>Tue, 23 Jun 2009 07:05:40 +0000</pubDate>
		<guid isPermaLink="false">http://dev.digi-corp.com/?p=692#comment-174</guid>
		<description>Hey really nice article.</description>
		<content:encoded><![CDATA[<p>Hey really nice article.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

