VBA crashes on "rowNum = objXLAppln.Range("A" & Rows.Count).End(xlUp).Row"

I have code that has the line "rowNum = objXLAppln.Range("A" & Rows.Count).End(xlUp).Row". Every once in a while the macro crashes on this line. It doesn't happen regularly or with a pattern. The entire code is below. I have several
modules that use this line of code. Any ideas?
Function ImportScores()
Dim RecSet As DAO.Recordset
Dim objXLAppln As Excel.Application
Dim objWBook As Excel.Workbook
Dim rowNum As Variant
Dim i As Integer
Dim j As Integer
Dim StrPathFile As String, strFile As String, strPath As String
Dim strBrowseMsg As String, strInitialDirectory As String, strFilter As String
'show dialogue box
strBrowseMsg = "Select the EXCEL file:"
'set directory to load files from
strInitialDirectory = "C:\Bridge_CIP_Part-A_B\"
'run strFilter function
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xlsx)", "*.xlsx")
StrPathFile = ahtCommonFileOpenSave(InitialDir:=strInitialDirectory, _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:=strBrowseMsg, _
Flags:=ahtOFN_HIDEREADONLY)
If StrPathFile = "" Then
MsgBox "No file was selected.", vbOK, "No Selection"
Exit Function
End If
'Set Excel application object. Critical for macro to run properly. Do not change.
Set objXLAppln = New Excel.Application
'Open workbook and worksheet to load data.
With objXLAppln
Set objWBook = .Workbooks.Open(StrPathFile)
objXLAppln.Visible = True
End With
Set RecSet = CurrentDb.OpenRecordset("Performance_Scores")
'Copy data from Excel cells to Access fields
objXLAppln.Sheets("Performance_Attributes").Select
rowNum = objXLAppln.Range("A" & Rows.Count).End(xlUp).Row
objXLAppln.Range("A10").Select
'Add records to table from Excel
With RecSet
For i = 0 To rowNum - 9
RecSet.AddNew
RecSet.Fields("CIP_ID").value = objXLAppln.ActiveCell.Offset(i, 0).value
RecSet.Fields("5YearScore").value = objXLAppln.ActiveCell.Offset(i, 53).value
RecSet.Fields("10YearScore").value = objXLAppln.ActiveCell.Offset(i, 54).value
RecSet.Fields("15YearScore").value = objXLAppln.ActiveCell.Offset(i, 55).value
RecSet.Fields("20YearScore").value = objXLAppln.ActiveCell.Offset(i, 56).value
RecSet.Update
Next i
End With
'Close everything
RecSet.Close
objWBook.Close SaveChanges:=False
objXLAppln.Quit
Set RecSet = Nothing
Set objWBook = Nothing
Set objXLAppln = Nothing
End Function

I rewrote as below.
But rather than doing it this way, I would create a linked table to this workbook and import the data using an Append query.
Function ImportScores()
    Const FOOTER_ROWS_TO_SKIP As Integer = 10
    Const COL_CIP_ID As Integer = 1
    Const COL_5YEARSCORE As Integer = 54
    Dim RecSet      As DAO.Recordset
    Dim objXLAppln  As Excel.Application
    Dim objWBook    As Excel.Workbook
    Dim objXLSheet  As Excel.Worksheet
    Dim rowNum      As Variant
    Dim row         As Integer
    Dim j           As Integer
    Dim StrPathFile As String, strFile As String, strPath As String
    Dim strBrowseMsg As String, strInitialDirectory As String, strFilter As String
    'show dialogue box
    strBrowseMsg = "Select the EXCEL file:"
    'set directory to load files from
    strInitialDirectory = "C:\Bridge_CIP_Part-A_B\"
    'run strFilter function
    strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xlsx)", "*.xlsx")
    StrPathFile = ahtCommonFileOpenSave(InitialDir:=strInitialDirectory, _
                                        Filter:=strFilter, OpenFile:=True,
                                        DialogTitle:=strBrowseMsg,
                                        Flags:=ahtOFN_HIDEREADONLY)
    'StrPathFile = "C:\Users\Tom\Documents\test.xlsx"        'testonly
    If StrPathFile = "" Then
        MsgBox "No file was selected.", vbOK, "No Selection"
        Exit Function
    End If
    'Set Excel application object. Critical for macro to run properly. Do not change.
    Set objXLAppln = New Excel.Application
    'Open workbook and worksheet to load data.
    With objXLAppln
        Set objWBook = .Workbooks.Open(StrPathFile)
        objXLAppln.Visible = True
        Set objXLSheet = objXLAppln.Sheets("Performance_Scores")
    End With
    rowNum = objXLSheet.UsedRange.Rows.Count
    'Add records to table from Excel
    Set RecSet = CurrentDb.OpenRecordset("Performance_Scores", dbOpenDynaset)
    With RecSet
        For row = 1 To rowNum - FOOTER_ROWS_TO_SKIP
            RecSet.AddNew
            RecSet.Fields("CIP_ID").Value = objXLSheet.Cells(row, COL_CIP_ID).Value
            RecSet.Fields("5YearScore").Value = objXLSheet.Cells(row, COL_5YEARSCORE).Value
            'etc.
            RecSet.Update
        Next row
    End With
    'Close everything
    RecSet.Close
    objWBook.Close SaveChanges:=False
    objXLAppln.Quit
    Set RecSet = Nothing
    Set objWBook = Nothing
    Set objXLAppln = Nothing
End Function
-Tom. Microsoft Access MVP

Similar Messages

  • Display range of rows

    Can anyone suggest me an efficent SQL which can return range of rows for example I want to display records with rownum>=20 and rownum<=40.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Uma Santharam:
    Can anyone suggest me an efficent SQL which can return range of rows for example I want to display records with rownum>=20 and rownum<=40. <HR></BLOCKQUOTE>
    Hi,
    You can not use equal to and greater then condition in rownum.
    Secondly if you want 20 and 40 to be included in range search then use rownum <21
    and rownum < 41.
    Try to use following query to solve your above said problem.
    select e1.empno from emp e1
    where rownum <10 and empno not in
    ( select e1.empno from emp e1 where rownum <5);
    null

  • How do I select a range of rows from an internal table in the debugger?

    Hi,
    I have a case where I wanted to delete a range of rows (several thousand) from an internal table using the debugger.
    It seems that rows can only be selected one at a time by selecting (clicking) on the far left side of the row.
    This is cumbersome, if not impossible when wishing to delete several thousand rows. 
    Other tools, such as Excel for example, allow for selecting a range of rows by selecting the first row and then holding the SHIFT key and selecting the last row and all rows in between will be selected.
    I can't seem to find the combination of keys that will allow this in the table (or structure) tab of the debugger.
    Is it possible to select a range of rows without having to select each row one at a time?
    Thanks for your help,
    Andy

    While it's a Table Control and should/could have a button to select all fields (or visible fields)...I don't think we can do it right now...I know it's a pain to select each row one at a time...but I don't we have any more options...
    Greetings,
    Blag.

  • Range and rows

    Hi folks,
    I never used range or rows before in analytic functions. I took some time to learn a bit about them but cant figure out why would you need to use it? Most of the things I needed I got from lead or lag functions. So whats the deal with window functions? Where are they useful?
    Best regards,
    Igor

    Hi, Igor,
    Igor S. wrote:
    Hi folks,
    I never used range or rows before in analytic functions. I took some time to learn a bit about them but cant figure out why would you need to use it? Most of the things I needed I got from lead or lag functions. So whats the deal with window functions? Where are they useful?What do you mean by "window function"?
    That term most commonly refers to functions that allow you to specify a window of consecutive rows in your data set, and the function will operate on the rows within that window. In that sense, most analytic functions are window functions.
    The default window is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. You only need to specify a windowing clause (that is, RANGE or ROWS) if you want to override that.
    For example, the following query shows the average salary from the scott.emp table, and the number of salaries that contribute to that average, two different ways. The columns cnt_sal and avg_sal use the default windowing, so the figures on each row include that row itself, and all earlier rows (where hiredate determines what is earlier). The columns cnt_60 and avg_60 include only the 60 days up to, but not including, the row itself. Notice that sometimes there are 0 rows in that window.
    SELECT       ename
    ,       hiredate
    ,       sal
    ,       COUNT (sal) OVER ( ORDER BY  hiredate )     AS cnt_sal
    ,       AVG (sal)   OVER ( ORDER BY  hiredate     )     AS avg_sal  
    ,       COUNT (sal) OVER ( ORDER BY  hiredate
                                RANGE BETWEEN  61 PRECEDING
                                AND          1 PRECEDING
                         )                    AS cnt_sal_60
    ,       AVG (sal)   OVER ( ORDER BY  hiredate
                                RANGE BETWEEN  61 PRECEDING
                                AND          1 PRECEDING
                         )                    AS avg_sal_60
    FROM      scott.emp
    ORDER BY  hiredate
    ;Notice that the formula for cnt_sal is exactly the same as the formula for cnt_sal, except that cnt_sal_60 specifies a RANGE. The same goes for avg_sal and avg_sal_60.
    Output:
    ENAME      HIREDATE         SAL    CNT_SAL    AVG_SAL CNT_SAL_60 AVG_SAL_60
    SMITH      17-DEC-80        800          1        800          0
    ALLEN      20-FEB-81       1600          2       1200          0
    WARD       22-FEB-81       1250          3 1216.66667          1       1600
    JONES      02-APR-81       2975          4    1656.25          2       1425
    BLAKE      01-MAY-81       2850          5       1895          1       2975
    CLARK      09-JUN-81       2450          6     1987.5          1       2850
    TURNER     08-SEP-81       1500          7 1917.85714          0
    MARTIN     28-SEP-81       1250          8   1834.375          1       1500
    KING       17-NOV-81       5000          9 2186.11111          1       1250
    JAMES      03-DEC-81        950         11 2147.72727          1       5000
    FORD       03-DEC-81       3000         11 2147.72727          1       5000
    MILLER     23-JAN-82       1300         12 2077.08333          2       1975
    SCOTT      19-APR-87       3000         13 2148.07692          0
    ADAMS      23-MAY-87       1100         14 2073.21429          1       3000Edited by: Frank Kulash on Apr 3, 2013 9:16 AM
    Added example from scott.emp

  • How do you find the range of a counter and what do you mean by time limit

    hi
    can any one please tell me how to find the range of a counter for an 6025e DAQ board
    thanks

    Use Adjacent counters.vi to read the counter size (24 bits for the PCI-6025E --> range = 0 to 2^24 -1).
    You can access it in :
    1)..\vi.lib\daq\ctr.llb\
    2) Function palette --> DAQ --> Counter --> Am9513 & 8253 Compatibility
    Please clarify your question about the time limit.

  • Select a range of rows to be displayed using ROWNUM

    I am trying to select a range of records to be displayed using Rownum
    It works using MINUS
    SQL> select rownum,department_id,department_name from departments where rownum <= 20
    minus
    select rownum,department_id,department_name from departments where rownum < 11;
    but does not work if a range is specified
    select rownum,department_id,department_name from departments where rownum >= 11 and rownum <= 20;
    What has gone wrong?
    Details of what I have tried are as follows:
    Connect to the sample schema HR
    SQL> connect hr/hr
    SQL> desc departments
    Name Null? Type
    DEPARTMENT_ID NOT NULL NUMBER(4)
    DEPARTMENT_NAME NOT NULL VARCHAR2(30)
    MANAGER_ID NUMBER(6)
    LOCATION_ID NUMBER(4)
    List all records in Departments
    SQL> select rownum,department_id,department_name from departments;
    ROWNUM DEPARTMENT_ID DEPARTMENT_NAME
    1 10 Administration
    2 20 Marketing
    3 30 Purchasing
    4 40 Human Resources
    etc......
    26 260 Recruiting
    27 270 Payroll
    27 rows selected.
    List the first 10 records in DEPARTMENTS
    SQL> select rownum,department_id,department_name from departments where rownum <= 10;
    ROWNUM DEPARTMENT_ID DEPARTMENT_NAME
    1 10 Administration
    2 20 Marketing
    etc.....
    10 100 Finance
    List row number from 11 to 20, but cannot no rows selected. Why?
    SQL> select rownum,department_id,department_name from departments where rownum >= 11 and rownum <= 20;
    no rows selected
    Use of MINUS can retrieve row number from 11 to 20
    SQL> select rownum,department_id,department_name from departments where rownum <= 20
    minus
    select rownum,department_id,department_name from departments where rownum < 11;
    ROWNUM DEPARTMENT_ID DEPARTMENT_NAME
    11 110 Accounting
    12 120 Treasury
    13 130 Corporate Tax
    14 140 Control And Credit
    15 150 Shareholder Services
    16 160 Benefits
    17 170 Manufacturing
    18 180 Construction
    19 190 Contracting
    20 200 Operations
    10 rows selected.

    For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on.
    Conditions testing for ROWNUM values greater than a positive integer are always false. For example, this query returns no rows:
    SELECT * FROM employees
    WHERE ROWNUM > 1;
    You can get the selected records based on the rownum using the inline query....
    SQL> select rownum, empno from emp;
    ROWNUM EMPNO
    1 7369
    2 7499
    3 7521
    4 7566
    5 7654
    6 7698
    7 7782
    8 7788
    9 7839
    10 7844
    11 7876
    ROWNUM EMPNO
    12 7900
    13 7902
    14 7934
    14 rows selected.
    SQL> select * from (select rownum rn, empno from emp) where rn > 2 and rn < 5;
    RN EMPNO
    3 7521
    4 7566

  • Delete a range of rows in Oracle Table

    How do i delete a range of values in Oracle Table using SQL Pus. For example i have iwanted to delete rows with user_id from 12344 ~ 12399

    ustin thanks for the earlier help. Part of the requiremnt is met, now the tester can delete the rage of rows from 'dropbox', table. I am quiet not done in my second of the requirement. And that is pull the first 100 or 200 etc rows from the parent table (user_auth), and delete them from (dropbox). user_auth does not get affected. I able to user rank and dense_rank by create_time against user_auth table, and get the first 100 or 200 rows. However when join with dropbox, for example dropbox.user_id=user_auth.user_id. Query get hunged. I am not sure do i need to write a procedure for this, or a can be acieved by SQL. This is a test env.
    SQL> desc user_auth
    Name Null? Type
    USER_ID NOT NULL NUMBER(10)
    USER_NAME NOT NULL VARCHAR2(32)
    ACCOUNT_STATUS_CODE NOT NULL NUMBER(3)
    PASSWD VARCHAR2(13)
    DEVICE_ID_TYPE VARCHAR2(10)
    DEVICE_ID VARCHAR2(36)
    OLD_MSISDN NUMBER(15)
    MASTER_LOCK_CODE VARCHAR2(3)
    PARTNER_ID NOT NULL NUMBER(3)
    CREATE_TIME NUMBER(10)
    MAIL_PROVISIONED NOT NULL NUMBER(1)
    PASSWD_TYPE_ID NUMBER(3)
    USER_ID is primary key.
    INDEX_NAME INDEX_TYPE UNIQUENES
    PK_USER_AUTH_USER_ID NORMAL UNIQUE
    I_USER_AUTH_USER_NAME_PARTNER NORMAL UNIQUE
    I_USER_AUTH_DEVICE NORMAL UNIQUE
    I_USER_AUTH_MSISDN NORMAL UNIQUE
    DROPBOX
    Name Null? Type
    USER_ID NOT NULL NUMBER(10)
    DROPBOX_ID NUMBER(10)
    UPDATE_TIME NUMBER(10)
    MESSAGE_TYPE VARCHAR2(64)
    MESSAGE BLOB
    SURVIVE_REBOOT NUMBER(1)
    DELETE_TIME NOT NULL NUMBER(10)
    No Primary KEY
    INDEX_NAME INDEX_TYPE UNIQUENES
    I_DROPBOX_USER_ID NORMAL NONUNIQUE
    I_DROPBOX_SURVIVE_REBOOT NORMAL NONUNIQUE
    If I run
    select user_id, create_time, rnk1 FROM
    (select user_id, user_name, to_char(convert_unix_time(create_time)) create_time, DENSE_RANK() OVER (ORDER BY user_name) rnk1 from user_auth where user_name LIKE '%stomp%_%')
    where rnk1 < 100
    I get the result. How do i select these first 100 rows in the dropbox and delete them. relationship is many to many.

  • Finding duplicate ranges for rows in a table

    Data in the table
    ROW NUM ID A_FROM A_TO B_FROM B_TO
    1 1 1 10 1 10
    2 1 1 20 2 20
    3 1 3 30 2 20
    4 2 10 20 10 20
    5 2 10 30 20 30
    6 3 10 20 10 20
    I want to identify rows based on "ID" columns which has overlaping range of data for column A and column B.
    example
    In above data based on ID 1 the row # 2 should be flagged due to the fact that col A_FROM and A_TO in row1 overlaps with row #1.
    Also, row #3 should be flagged due to the fact that col B_FROM and B_TO in row2 overlapps with row #2.
    Any help is appreciated.

    TABLE - "rate_table"
    ID     A_FROM     A_TO     B_FROM     B_TO     RATE
    1     10     20     100     200     0.5
    1     10     30     201     300     0.25
    1     31     40     200     300     0.25
    2     10     20     1000     2000     0.275
    2     21     30     1000     2000     0.385
    3     10     20     1000     2000     0.658
    3     10     30     2000     5000     0.541
    3     31     40     1000     2000     0.695
    Above table is being used to update another table based on ID column
    Update Statement
    Update table1 t
    set t.rate = (select r.rate from rate_table r
    where t.id = r.id and
    (t.col_a between r.a_from and r.a_to) and
    (t.col_b between r.b_from and r.b_to) )
    where exists
    (select 0 from rate_table r
    where t.id = r.id and
    (t.col_a between r.a_from and r.a_to) and
    (t.col_b between r.b_from and r.b_to) )
    This update would return error
    "ORA-01427: single-row subquery returns more than one row"
    This is due to the fact that while matching records against table TABLE1 to RATE_TABLE, the range for specific ID are overlapping.
    My question.
    How can I identity or avoid ORA-01427 error on the update statement? or how do i identity overlapping range records in RATE_TABLE?

  • Photoshop CC crashes when selecting "Color Range"

    Hi, my Photoshop CC crashes whenever I click on "Color Range" under "Select". It shows "Photoshop CC has stopped working".
    It seems like no one I know can fix my problem. Can any kind souls out there who could advise if it's due to certain of my PC configurations, and how I could resolve this issue?
    Thanks a million for reading!!

    We can't know. You have not provided any system information or details about your document. Quite likely you simply have color profile or hardware acceleration issues, so update your graphics driver.
    Mylenium

  • Why rownum 5 return no rows selected

    hi
    i want to know why rownum >5 .. is give no rows selected
    eg
    select * from emp where rownum>5;
    .....

    Because Oracle assigns a row number after it's actually been selected for outputting. In other words after the where condition has been satisfied.
    So, it looks at the first row and then sees if it's rownum (1) is greater than 5 - it isn't
    It looks at the next row (whose rownum is still 1 as we haven't selected anything for output yet). It still isn't greater than 5.
    ...and so on.
    But rownum < 5 will work. It will get you 4 rows.
    Note that sorting taking place after all this so
    select *
    from emp
    where rownum < 5
    order by emp_no;Will NOT get you the first 4 rows ordered by emp_no. Rather it will get you 4 arbitrary rows and then sort them by emp_no.
    So, back to your problem. It is probably best to use row_number rather than rownum:
    select *
    from (
      select e.*, row_number() over (order by empno) rnum  from emp e
    where rnum > 5;

  • Libreoffice calc crash after editing named range

    i have a freshly installed arch system, so everything is up-to-date. however, my calc (ver. 4.2.4.2) crash after editing (and save) named range. this bug supposed to be fixed in previous version.
    https://bugs.freedesktop.org/show_bug.cgi?id=78226

    i have a freshly installed arch system, so everything is up-to-date. however, my calc (ver. 4.2.4.2) crash after editing (and save) named range. this bug supposed to be fixed in previous version.
    https://bugs.freedesktop.org/show_bug.cgi?id=78226

  • Rownum and last inserted row !!!!!!!!!!!!

    hi everybody,
    I am at present using oracle 8i Release 2. According to my knowledge and "Oracle 8 complete reference", when we use ROWNUM, the rownum is decided when the data is selected from the database. So when we use "order by" clause actually the rownum gets jumbled up.
    But to my surprise when i did something like this on my SQl prompt row num is acting very "innocent" :)
    <Code>
    1* select rownum, empno from emp
    SQL> /
    ROWNUM EMPNO
    1 7369
    2 7499
    3 7521
    4 7566
    5 7654
    6 7698
    7 7782
    8 7788
    9 7839
    10 7844
    11 7876
    12 7900
    13 7902
    14 7934
    15 1
    15 rows selected.
    SQL> select rownum, empno from emp order by empno;
    ROWNUM EMPNO
    1 1
    2 7369
    3 7499
    4 7521
    5 7566
    6 7654
    7 7698
    8 7782
    9 7788
    10 7839
    11 7844
    12 7876
    13 7900
    14 7902
    15 7934
    15 rows selected.
    </Code>
    As you can see rownum is ordered again .. m i missing something.
    B)
    Is it possible to get a row that was inserted last. Does oracle guarantee that data retrieval will be according to the time of inssertion !!
    Thanx in advance
    Chetan

    Rownum is decided afeter the complete execution of ur SQL statment (it includes ordey by, group by, where etc.).
    you can get the last inserted row using:
    select * from emp where rowid=
    (select max(rowid) from emp);
    Regards
    Riaz

  • ADF Master Table, Inline Detail Table - How to Scroll Range/Disclose Row

    JDev 10.1.3.2 ADF/BC
    I really need some help here. I've tried as many things as I could think of and I still cannot get this to work.
    Scenario: I have query/result page. User clicks a link in the result table to take him to another page. This page has a Master table, Inline detail table component (bound to a tree in the pageDef). Before the page renders, all I want to do is scroll the Master table to the current row (based on the previous query/result via invokeAction in pageDef) and disclose the inline detail. Simple, right? In addition, I'll need to scroll the inline detail to the current row as well.
    I would like to do this prior to the components rendering but would be interested in any coding to scroll and disclose.
    Thanks in advance,
    Tom

    I've come up with a solution to my problem. Unfortunately I'm not able to manipulate the table prior to rendering but this solution is probably the closest I'm going to get. Here is my code:
    I set up a af:poll component to fire once on my jspx.
        public void poll_PollListener(PollEvent pollEvent) {
            if (this.getFromProcess("unitRowKeyValue") != null) {
                int curIndx = this.getIteratorBinding("UnitsIterator").getRowSetIterator().getCurrentRowIndex();
                this.getUnitTree().setFirst(curIndx);
                if (this.getFromProcess("systemRowKeyValue") != null) {
                    this.getUnitTree().setRowIndex(curIndx);
                    DisclosureEvent de = new DisclosureEvent(this.getUnitTree(), true);
                    this.getUnitTree().queueEvent(de);
                this.storeOnProcess("renderPoll", false);
        }The setFirst method scrolls the table to the index specified. If the user, in my case, has selected a detail item (system), I want to disclose the detail. First I need to setRowIndex to the current index and then I fire a disclose event.
        public void unitTreeDisclosureListener(DisclosureEvent disclosureEvent) {
             if (disclosureEvent.isExpanded()) {
                 CoreTable coreTable = (CoreTable)disclosureEvent.getSource();
                 RowKeySet rks = new RowKeySet();
                 Object test = coreTable.getRowKey();
                 rks.getKeySet().add(coreTable.getRowKey());
                 coreTable.setDisclosureState(rks);
          }If I don't set the rowKey via the setRowIndex method above, the getRowKey does not return a valid rowKey. In my case, I only want one master row to be disclosed at a time.
    This all works great except for a bit of flicker to process the PPR request for the component.
    Next step is to see if I can scroll the Inline Detail table to the detail row selected in the Query/Result page.
    Tom

  • Select a range of rows?

    I know I can edit SELECT TOP (200) to increase rows, but how can I select NEXT 200 rows or rows 200 thru 400? I have tried OFFSET, START AT, SKIP, etc.

    Of course.
    you can create a stored procedure like this
    create PROCEDURE [dbo].[usp_GetPersons]
    @rowsperpage int = 200
    , @pagenumber int = 1
    AS
    BEGIN
    SET NOCOUNT ON;
    ;with cte
    as (
    SELECT *, ROW_NUMBER() OVER (ORDER BY [BusinessEntityID]) AS RowNumber
    FROM [Person].[Person]
    select
    from
    cte
    WHERE RowNumber BETWEEN ((@PageNumber-1)*@RowsPerPage)+1
    AND @RowsPerPage*(@PageNumber)
    SET NOCOUNT OFF;
    END
    and after that you can execute
    EXEC [dbo].[usp_GetPersons] @rowsperpage = 200, @pagenumber = 1
    go
    with this results
    and so on
    EXEC [dbo].[usp_GetPersons] @rowsperpage = 200, @pagenumber = 2
    go
    I hope this will help you
    P. Ceglie - "CIA - Is the main thing" ______________________________________________ Se alcuni post rispondono al tuo quesito(non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post
    utili. La community ringrazia :-)

  • All months in date range plus running count

    Oracle 11g
    Hello all,
    Having trouble getting the following query to return proper results. Have a table with a MEMBERNO, BUSINESS_LINE, ELIGIBILITY_START_DATE, ELIGIBILITY_END_DATE.
    MEMBERNO is not unique
    BUSINESS_LINE is not either
    Start and end date are periods of time where: MEMBERNO&BUSINESS_LINE have changed
    I need to list the member number, business_line, and each month that falls within the date range beginning with eligibility_start_date & eligibility_end_date, as well as a running count of the total in that span.
    Eg.
    member, business_line, month, year, count
    1234, bus1, 01, 2001, 1
    1234, bus1, 02, 2001, 2
    1234, bus1, 03, 2001, 3
    Here is my SQL, it is not sequencing the months dates correctly and I can not figure out why. Any help is very appreciated:
    SELECT memberno,
    business_line,
    TO_CHAR (ADD_MONTHS (start_date, LEVEL - 1), 'MM') as MONTH,
    TO_CHAR (ADD_MONTHS (start_date, LEVEL - 1), 'YYYY') as YEAR,
    ROW_NUMBER () OVER (PARTITION BY key1 ORDER BY start_date ASC) as MEMBER_MONTH_COUNT
    FROM (SELECT memberno,
    business_line,
    eligibility_start_date as start_date,
    eligibility_end_date as end_date,
    member_nbr || business_line as key1
    FROM eligibility)
    CONNECT BY LEVEL <=
    MONTHS_BETWEEN (TRUNC (END_DATE, 'MM'),
    TRUNC (START_date, 'MM'))
    + 1;
    Edited by: 935047 on Jul 25, 2012 5:58 AM
    Edited by: 935047 on Jul 25, 2012 6:18 AM

    935047 wrote:
    I need to list the member number, business_line, and each month that falls within the date range beginning with eligibility_start_date & eligibility_end_date, as well as a running count of the total in that span.
    Eg.
    member, business_line, month, year, count
    1234, bus1, 01, 2001, 1
    1234, bus1, 02, 2001, 2
    1234, bus1, 03, 2001, 3I could not understand what the Running Count mean. Hence, I used Row_Number (Same as you did).
    Below query might match yours.
    with data (memb_no, bus_line, st_date, end_date) as
      select 1234, 'bus1', to_date('01-01-2001', 'MM-DD-YYYY'), to_date('06-30-2001', 'MM-DD-YYYY') from dual
      union all
      select 1234, 'bus1', to_date('07-01-2001', 'MM-DD-YYYY'), to_date('07-30-2002', 'MM-DD-YYYY') from dual
    min_max as
      select memb_no, bus_line, min(st_date) st_date, max(end_date) end_date
        from data
       group by memb_no, bus_line
    lvl as
      select level l
        from dual
      connect by level <= (select max(round(months_between(end_date, st_date))) from min_max)
    select memb_no,
           bus_line,
           to_char(add_months(st_date, l - 1), 'MM') months,
           to_char(add_months(st_date, l - 1), 'YYYY') Year,
           row_number() over (partition by memb_no, bus_line order by st_date) cnt
      from min_max cross join lvl
    order by year, months;
    ----OUTPUT------------------------
    MEMB_NO BUS_LINE MONTHS YEAR CNT
       1234 bus1     01     2001   1
       1234 bus1     02     2001  19
       1234 bus1     03     2001   3
       1234 bus1     04     2001   4
       1234 bus1     05     2001   5
       1234 bus1     06     2001   6
       1234 bus1     07     2001   7
       1234 bus1     08     2001   8
       1234 bus1     09     2001   9
       1234 bus1     10     2001  10
       1234 bus1     11     2001  11
       1234 bus1     12     2001  12
       1234 bus1     01     2002  13
       1234 bus1     02     2002  14
       1234 bus1     03     2002  15
       1234 bus1     04     2002  16
       1234 bus1     05     2002  17
       1234 bus1     06     2002  18
       1234 bus1     07     2002   2
    19 rows selected

Maybe you are looking for

  • Mapping routine in ABAP OO

    Hi, I created a transformation in BI and need to fill one field with a value read from a master data table. In the version 3.X this could be done with following ABAP routine: tables: /BI0/PGL_ACCOUNT. data: wa type /BI0/PGL_ACCOUNT.      select singl

  • Sharepoint Report Subscriptions not showing on sharepoint website, but are in the database

    Hi All, We have had an issue which sharepoint where our subscriptions for reports "disappear" from the website. This makes is a little hard to edit them if we need to adjust the subscription. The funny thing is the subscription is still working as it

  • Share library between MAC accounts

    I have an iMac with three user accounts, how do we share common items such as photo's in iPhoto and songs/videos in iTunes in such a way that maintains iPhoto event structures and iTunes playlists. Michael,

  • WRT320N - How to close ports

    Certain ports I will hardly or ever use like: SMTP 25, telnet 23, SNMP 161, etc I want to make my network more secure by closing some ports, but how is this done? The manual says nothing about such feature. Thank you.

  • SAP XI and Lotus Notes

    Hello, Is there a best approach followed now to integrate XI and Lotus notes. We have a requirement to create a lotus notes document from SAP R3 using XI. Any suggestions and successful implementations please... Thank you Thilothama