A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
How to Convert Cursor into While Loop In SqlServerThis article is about how we can change the cursor in the while loop in SQL Server. It's very useful in improving the performance of stored procedures. |
On Sunday, June 27th 2010 at 10:36 PM By Kuldip Bhatt (View Profile) ![]() ![]() ![]() ![]() (Rated 0 with 0 votes) |
||
|
I personally face this issues in many Store Procedures i.e. Cursor taking too much time to execute. I am sure many of you will be having similar problem. I have worked on that issue and found following solution. It may not be perfect for cursor optimization but it does work in my case. Original Cursor Code Declare @fk_MedicationOrderId as Bigint Declare @AdminTime as Bigint declare CUR_MEDICATIONORDERID cursor FOR select fk_MedicationOrderId from tbl_medicationorderDetail_trn where Actiondate > Getdate() OPEN CUR_MEDICATIONORDERID FETCH NEXT FROM CUR_MEDICATIONORDERID INTO @fk_MedicationOrderId WHILE @@FETCH_STATUS =0 BEGIN Select @AdminTime=AdminTime from tbl_medicationorderDetail_trn where fk_medicationorderid = @fk_MedicationOrderId Update tbl_TempMedicationOrderDetail_trn set ActionTime = @AdminTime set @AdminTime = FETCH NEXT FROM CUR_MEDICATIONORDERID INTO @fk_MedicationOrderId END CLOSE CUR_MEDICATIONORDERID DEALLOCATE CUR_MEDICATIONORDERID - Modified Cursor Code (faster) Declare @fk_MedicationOrderId as Bigint Declare @AdminTime as Bigint Declare Table for the fields you need in the cursor. declare @IDList table (ID Bigint) Insert into @IDList select fk_MedicationOrderId from tbl_medicationorderDetail_trn where Actiondate > Getdate() while (select count(ID) from @IDList) > 0 begin select top 1 @fk_MedicationOrderId = ID from @IDList Select @AdminTime=AdminTime from tbl_medicationorderDetail_trn where fk_medicationorderid = @fk_MedicationOrderId Update tbl_TempMedicationOrderDetail_trn set ActionTime = @AdminTime set @AdminTime = delete from @IDList where ID = @fk_MedicationOrderId end - What I have done here is to convert cursor into while loop. It is just to get your data in any temporary table or table variable after that just delete the rows from that at end of loop. It helps in improving performance, I have personally tried it in many stored procedures. Let me know if you find any other useful way of improving performance. |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current Commentsdelete from @IDList where ID = @fk_MedicationOrderId
http://www.gucciusaoutlet.net/index.php?main_page=index
I am agree with <a href=" http://www.uggssalecheap.com" > uggs for cheap</a> idear,
Welcome to our website <a href="http://www.uggssalecheap.com" >uggs sale online</a>;
<a href="http://www.uggssalecheap.com" >uggs on sale</a>;
I am agree with <a href=" http://www.uggssalecheap.com" > uggs for cheap</a> idear,
Welcome to our website <a href="http://www.uggssalecheap.com" >uggs sale online</a>;
<a href="http://www.uggssalecheap.com" >uggs on sale</a>;
I am a short girl, and I am afraid of wearing replica day date watches seeing as long seeing as the summer comes. I am not confident at all because of my short legs. Later I find that actually short girls could also wear swiss replica watches at any time seeing as long seeing as they know the skills to complement their clothes, whatβs more, they could also appear taller by proper matching ways.
<a href="http://www.watcheslux.com/tissot-watches.html">Tissot replica watches</a>
Related Tutorials
Related Source Code
SQL Job Search