How can I replace the cursor in the below query?

I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are
required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.
DECLARE db_cursor_ava CURSOR
FOR
SELECT t.[agent-id],
t.[start-date],
t.[end-date],
t.[monitor-days],
t.[monitor-start],
t.[monitor-end],
t.[timezone-offset]
FROM @tmpAgentPeriodTimeRange t
OPEN db_cursor_ava
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE
FROM @tmpMonitorPeriod
DELETE
FROM @tmpFinalResult
SET @runID = 1
IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
BEGIN
SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
END
INSERT INTO @tmpMonitorPeriod
EXEC core.usp_GetMonitoringPeriod
@startDate = @stDateTime_ava,
@endDate = @endDateTime_ava,
@monitoringDays = @monDays_ava,
@monitoringStart = @monSt_ava,
@monitoringEnd = @monEnd_ava
SELECT @maxID = MAX(tm.id)
FROM @tmpMonitorPeriod tm
FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
@stDateTime_ava,
@endDateTime_ava,
@monDays_ava,
@monSt_ava,
@monEnd_ava,
@offset_ava
END
CLOSE db_cursor_ava
DEALLOCATE db_cursor_ava
mayooran99

You've been down this path before  - and the response is exactly the same.
how to replace cursor logic
And I'll suggest that you post the entire code - since you repeatedly delete 2 table variables but only populate one. The setting of @maxID also seems to have no purpose. And perhaps the issue here isn't the cursor but the general approach.  Who knows
- but it appears you may have prematurely assumed that the cursor is the problem.

Similar Messages

  • How can I keep my cursor on the screen ?

    my cursor on my imac goes off the screen.  How can I control it?

    Thanks for your reply, but I am talking about tasks not events. I can see my events, I cannot see any tasks below that. I used to be able to, but they have disappeared. I can plan a new task, but it never shows anywhere on my screen after i have planned it.
    Cheers,
    Russ Kent

  • How can I replace ALL Contacts on the iPhone with my MobileMe Contacts?

    I have removed all duplicates in AddressBook on my various Macs and have uploaded the master copy to MobileMe. I would now like to replace all Contacts on my iPhone with that MobileMe master.
    I have followed the steps in the KB article for syncing the iPhone but when I get to the step of turning on the iPhone Settings for the Contacts it looks like the sync wants to merge the contacts. Of course, I do not want to "merge" since that will reintroduce all those duplicates.
    I suppose I could manually delete each of the the hundreds of contacts that are on my phone until it is empty ... and then turn on the iPhone setting for Contacts. That way it will have no option other than "add." But surely there is a more efficient way.
    (FWIW, when I turned OFF the setting for the Calendar it did empty the iPhone's calendar, which is what I wanted. But it didn't do that for the Contacts -- I turned that setting off but I was not asked if I wanted to keep or toss the Contacts. They are all still on the phone.)
    This is an OG iPhone, if that matters.

    Matthew Smith wrote:
    ... The only way I can think of doing it otherwise is possibly by syncing via iTunes via another Mac OS X user account where the address book is empty and then deleting them there and resyncing. ...
    Brilliant! That worked like a charm.
    I created a new User Account on one of my Macs and logged into it. I connected my iPhone to its iTunes and checked my iPhone's Sync Contacts option in iTunes. Since that account's address book was basically empty (two dummy contacts, one for Apple and one for this new user), I ended up with only those two Contacts on the phone. Then, going back to my real User account (which does not have syncing turned on in iTunes) the phone synced nicely with the MobileMe account and populated the phone with all the MobileMe contacts and groups.

  • My output channel strip is in the middle of my mixer. How can I replace it next to the master?

    In the mixer window of Logic Pro the output channel strip has moved to the middle of the audio strips. How can I move it back to its usual spot next to the master strip?

    Sounds like you have created an Aux track for your Output channel strip, and the position of that track on the arrange page now determines the place of the output channel strip on your mixer. So, you'll have to move that track so it is the bottom track in the arrangement, then the output channel strip in the mixer should move to the right again.
    It is a sorely missed (and often requested) feature to be able to move channel strips around freely in the mixer.

  • Is there any way to replace my iphone 5. The back camera is not working. Since there's no apple store here in the philippines. How can i replace it?

    How can i replace it?

    You probably do in NZ ..................
    The Apple iphone warranty is not and never has been from the very first iPhone, international
    Sorry but you were stitched up

  • I bought a mac air retina to replace a mac pro. How can I get all files of the back up and copy them to the new mac?

    I bought a mac air retina to replace a mac pro. How can I get all files of the back up and copy them to the new mac?

    Mail window may be in the Full Screen mode.
    Move the mouse pointer to the top right corner of the Mail window and hold it there.
    Menu bar should drop down and click the blue double arrow icon.
    Full Screen toggle shortcut:  control + command + F

  • Safari status bar disappears.  I have tried clicking on show status bar and it will only appear when I move the cursor to the top of the screen.  I can not minimize the open page only full screen or close the browser.  Any idea how the rectify this

    Safari status bar disappears. I have tried clicking on show status bar, under the View tab and it will only appear when I move the cursor to the top of the screen. I can not minimize the open page, only full screen or close the browser. Any idea how the rectify this issue?

    One enters and exits full-screen with control+command+F keys. This is on the View menu in Safari. Optionally, the green traffic light in your browser title bar, if you roll over it, has the full-screen control it it. While in full-screen mode with Safari, moving your mouse pointer virtually up, and off-screen reveals the Safari title bar again, and you can click the green traffic light to exit full-screen mode.
    You can hide/show the status bar by simply typing command+/. This too, is on the Safari View menu. and in 10.10.1 — it works reliably for me.

  • How can i replace the battery of an iPad 2?

    How can I replace the battery of an 3.5 year old IPAD 2?
    battery is empying fast compared to when I bought it and I would want to give this to my parents

    Apple will replace the battery for you. See here for details: https://www.apple.com/batteries/replacements.html

  • How i can fixup the cursor in the center of plot at any time?

    i need the cursor show the data of the points in plot,but i found after the plot zoomin,the cursor can not show .how i can fixeup the cursor at any time?
    thanks a lot.

    Hi Longsan,
    So I tried to reproduce the issue you were seeing and I believe I know what is going on. If you zoomin and the max and min of the axes are smaller than the cursor position, the cursor will no longer be in the viewing area of the graph. Therefore, you would want to reposition the cursor after you zoom in. For example, in Visual Basic you could use the command
    CWGraph1.Cursors(1).XPosition to change the position. I thiss out and it seems to work correctly. Let me know if try this and you are still having trouble.
    Thanks,
    Caroline
    National Intruments
    Thanks,
    Caroline Tipton
    Data Management Product Manager
    National Instruments

  • How can I move the cursor in the ResultSet?

    Hi all,
    The following is part of my coding...
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
             ResultSet codes = getCodes();
            try
                    codes.first();          
                    Code c = getCode (codes);
                    jLabel8.setText(c.scode);
                    jTextField2.setText(c.name);
                    jLabel9.setText(c.ic);
                    jTextField4.setText(c.add);
                    jTextField5.setText(c.phone);
            catch (SQLException e)
                System.out.println(e.getMessage());
        private static ResultSet getCodes()
            Connection con = getConnection();
            try
            Statement s = con.createStatement();
            String select = "SELECT [Student-File].* " + "FROM [Student-File];" ;
            ResultSet rows;
            rows = s.executeQuery(select);
            return rows;
            catch (SQLException e)
                System.out.println(e.getMessage());
            return null;
        } I would like to moves the cursor to the first row in the ResultSet object...
    But an error occured...
    Result set type is TYPE_FORWARD_ONLY
    I have tried to change
    Statement s = con.createStatement();to
    Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE);But a warning existed...
    cannot find symbol
    symbol : method createStatement(int)
    location : interface java.sql.Connection
    Can anyone help me?Thanks.
    Ning.

    Hi,
    Actually I would like to create 2 button, one is named as NEXT, another one is named as PREVIOUS. Once i click on the NEXT or PREVIOUS button, a query statement will be executed to retrieve the information of all of the student in a table. At the same time, the name, student code, address, ic and phone number of a student will be displayed by label respectively. After that, if I click on the NEXT button, the information of the current student will be replaced by the information of the next student. By the way, if I click on the PREVIOUS button, the information of the current student will be replaced by the information of the previous student.
    Ning.

  • HT4060 how can i replace the battery on my ipad? it wont charge all the way

    my ipad will only charge to 14% then goes down...how can i replace the battery?

    iPad Owners
    Your one-year warranty includes replacement coverage for a defective battery. You can extend your coverage to two years from the date of your iPad purchase with the AppleCare Protection Plan for iPad. During the plan’s coverage period, Apple will replace the battery if it drops below 50% of its original capacity. If it is out of warranty, Apple offers a battery replacement for $99, plus $6.95 shipping, subject to local tax. Apple disposes of your battery in an environmentally friendly manner.
    http://www.apple.com/batteries/replacements.html

  • How can I replace the Special Character        '

    Hi Guru ,
    I want replace one Special Chareacter into space .
    Example -
    There have one variable .
    L_VAR = BANGA'LORE
    I want to delete the special character ( ' ) which is between A and L .
    Whenever I am tryiny to use replcae statement , it will show one Error Message .
    REPLACE ''' IN L_VAR WITH ' '.
    IT WILL GIVE ONE ERROR MESSAGE - " Literals that take up more than one line are not permitted."
    How Can I replace this .

    Hi Tarak Dey,
    This error
    Literals that take up more than one line are not permitted
    is not for the Replace statement. You would have missed a PERIOD in some statement before this.
    When we see the code that you have pasted,
    L_VAR = BANGA'LORE
    here period is missing at the end of the line. The error could be because of that.
    Kindly check.
    Best Regards,
    Ram.

  • How can i replace the standard ESS iview with my own iview

    I want to replace standard ESS addr iview with my own WD developed by ABAP
    I added the iview(my WDA) into standard ESS addr page.
    (pcd:portal_content/com.sap.pct/every_user/com.sap.pct.erp.ess.bp_folder/com.sap.pct.erp.ess.pages/com.sap.pct.erp.ess.personal_information/com.sap.pct.erp.ess.cn/com.sap.pct.erp.ess.addr/com.sap.pct.erp.ess.addr)
    And make it visible.
    But I got this error in ESS PA addr :
    WebDynpro Exception: Application PER_ADDRESS_CN Does Not Exist
    Here is the error code :
    Error code:ICF-IE-http-c:100-u:AC_WANGFZ-l:1-s:CE1-i:SAPCE101_CE1_01-w:0-d:20070514-t:172301-v:RABAX_STATE-e:UNCAUGHT_EXCEPTION
    So , how can i replace the standard ESS iview with my own iview?
    Thanks

    Can you see any Javascript EPCF code in the old iView  ?  You are surely just going to have to find it  (if our hunch is correct) and analyse it and copy it into your new iView so that it functions in some way that at least does not error

  • How can I replace the old commenting system with Disqus?

    How can I replace the old commenting system on Business Catalyst with Disqus? Please help

    Hi,
    The Disqus integration has been done by at least one BC partner – simpleflame.com, on this site: http://kiyuco.com/free-videos . You could reach out to them inquiring for more details on how it has been done.
    Kind regards,
    -Sidney

  • How can I replace the SIM on Droid Ultra?

    How can I replace the SIM on Droid Ultra?

    SIM cards are free at your local Corporate Verizon store.
    SIM Card - Inserting/Removing - DROID Mini / DROID Ultra / DROID Maxx by Motorola

Maybe you are looking for

  • My HP Color LaserJet CP1518ni printer re-configures every time I initiate a print demand.

    Every single time I initiate a print job, this printer re-configures. I can have ten different pages that I want to print and regardless of the amount of time it takes me to set up the next page. this maching re-configures before printing the next pa

  • Explorer Context Menu Convert Sends Files to the Printer

    Right-clicking PSD files and choosing "convert to PDF" sent the files to the printer!!!  I had hoped it would have brought up a dialog to convert the files to PDF... (I was looking for "combine as PDF" -- I'm not sure what happened to it?) I'm runnin

  • 12 days of gifts is a scam?

    Hello, I got the app "12 Days" from iTunes.. which should give free gifts due the christmas time. Yesterday the gifst was BBC Series "Africa" , I pressed to get this gift and today got the reciept of 12.99pound from my account. I didnt even download

  • Contacts won't save in my iPad....... Help!

    The done button doesn't do anything, so I have to click on cancel and the info is not saved... Any hints?

  • ITunes and iPod not working with one account

    Hi I have iTunes 9.0.1 running on 10.6.1 on a MBP and I have just bought a new 5th generation iPod Nano. I have been trying to set up the iPod on my partner's account on my MBP. iTunes just freezes every time I plug in the iPod and needs a force quit