ROW_NUMBER and paging
hello
A simple question on paging/ROW_NUMBER. The following sql is fine.
select PersonId, Logon, IsSuspended, ROW_NUMBER() OVER(ORDER BY Logon ASC) RowNumber FROM Person;
Now to do paging (retrieve only record 1 to 10), I added the WHERE clause:
select PersonId, Logon, IsSuspended, ROW_NUMBER() OVER(ORDER BY Logon ASC) RowNumber FROM Person WHERE RowNumber>1 AND RowNumber<10;
But the complaint was:
ORA-00904: "*ROWNUMBER*": invalid identifier
Of course I can INSERT into a temp table first then select off the temp table but... I don't need to resort to this right?
Thanks
ah... ROWNUM does it.Not the way you think it does....
SQL> select count(*) from emp
2 /
COUNT(*)
14
Elapsed: 00:00:00.03
SQL> select ename, sal from emp where rownum > 1
2 /
no rows selected
Elapsed: 00:00:00.01
SQL>You have to alias it, inside an inline view. It fact, just like ROW_NUMBER().
The other thing which concerns me is the word "paging" in the subject. This is the wrong way to handle paging of rows in a multi-row block. Your client program should handle both the paging and the fetching of rows from a resultset.
Cheers, APC
blog: http://radiofreetooting.blogspot.com
Similar Messages
-
SAP ECC6 memory and paging issues
Dear Experts
I have recently upgraded my 4.6C systems to an ECC 6 system (DB2 LUW 9.5 on AIX 5.3 TL9 64 Bit OS)
I have been running the LPAR with 14 GB of memory and we are around 100-200+ users using the system, I was monitoring using nmon and found that Physical Memory was around 99.8% Used (14311.8MB and 22.6MB was free) also the paging space was around 37.2% in result causing the system at times to run slow which can have a very negative effect on the users.
After further investigation I found that after a system restart the Physical Memory would start around 50.9% and increased at a steady pace until it reached 99.8% that is when the system would start using the paging space which would steadily increase, I found that the only solution was a system restart at least once a week to reduce the memory consumption.
At first glance it looked like a database manger memory leak with the process db2sysc, so I searched the net with the search words u201Cdb2 memory leaku201D and found the following APARs and notes.
APAR JR30285 - Pervasive memory leak when compiling SQL statements that use SQL/XML functions
APAR IZ35230 - There is a pervasive unix-specific private memory leak in the security component
Note 1288341 - Memory leak in APPLHEAPSZ -> SQL0954C
Note 1352361 - Memory leak in shared memory area abrfci
Note 1147821 - DB6: Known Errors and available Fixes in DB2 9.5 LUW
After reading the notes and APARs I decided to updated DB2 to the latest fix pack (5SAP), but after the fix pack was implemented it did not solve the memory problem
I started look at different problems with SAP ECC6, db2 and AIX with paging/memory problems and I found the following notes to do with AIX memory and paging but none of them helped as all parameters and settings were set accordingly
789477 - Large extended memory on AIX (64-bit) as of Kernel 6.20
191801 - AIX 64-bit with very large amount of Extended Memory
973227 - AIX Virtual Memory Management: Tuning Recommendations
884393 - AIX saposcol consumes large amount of memory.
856848 u2013 AIX Extended Memory Disclaiming
1048686 u2013 Recommended AIX settings for SAP
1121904 u2013 SAP on AIX: Recommendations for Paging
1086130 u2013 DB6: DB2 Standard Parameter Settings
After even more investigation I found the following evidence suggesting AIX Virtual Memory Manager might have a problemShared memories inside of pool 40
Key: 42 Size: 17792992 ( 17.0 MB) DB TTAB buffer
Key: 43 Size: 53606392 ( 51.1 MB) DB FTAB buffer
Key: 44 Size: 8550392 ( 8.2 MB) DB IREC buffer
Key: 45 Size: 7014392 ( 6.7 MB) DB short nametab buffer
Key: 46 Size: 20480 ( 0.0 MB) DB sync table
Key: 47 Size: 10241024 ( 9.8 MB) DB CUA buffer
Key: 48 Size: 300000 ( 0.3 MB) Number range buffer
Key: 49 Size: 2769392 ( 2.6 MB) Spool admin (SpoolWP+DiaWP)
Shared memories outside of pools
Key: 3 Size: 114048000 ( 108.8 MB) Disp. communication areas
Key: 4 Size: 523048 ( 0.5 MB) statistic area
Key: 6 Size: 692224000 ( 660.2 MB) ABAP program buffer
Key: 7 Size: 14838 ( 0.0 MB) Update task administration
Key: 8 Size: 134217828 ( 128.0 MB) Paging buffer
Key: 9 Size: 134217828 ( 128.0 MB) Roll buffer
Key: 18 Size: 1835108 ( 1.7 MB) Paging adminitration
Key: 19 Size: 119850000 ( 114.3 MB) Table-buffer
Key: 41 Size: 25010000 ( 23.9 MB) DB statistics buffer
Key: 63 Size: 409600 ( 0.4 MB) ICMAN shared memory
Key: 64 Size: 4202496 ( 4.0 MB) Online Text Repository Buf.
Key: 65 Size: 4202496 ( 4.0 MB) Export/Import Shared Memory
Key: 1002 Size: 400000 ( 0.4 MB) Performance monitoring V01.0
Key: 58900114 Size: 4096 ( 0.0 MB) SCSA area
Nr of operating system shared memory segments: 16
Shared memory resource requirements estimated
================================================================
Total Nr of shared segments required.....: 16
System-imposed number of shared memories.: 1000
Shared memory segment size required min..: 692224000 ( 660.2 MB)
System-imposed maximum segment size......: 35184372088832 (33554432.0 MB)
Swap space requirements estimated
================================================
Shared memory....................: 1654.8 MB
..in pool 10 328.6 MB, 58% used
..in pool 40 143.3 MB, 30% used
..not in pool: 1174.1 MB
Processes........................: 413.4 MB
Extended Memory .................: 6144.0 MB
Total, minimum requirement.......: 8212.2 MB
Process local heaps, worst case..: 3814.7 MB
Total, worst case requirement....: 21882.9 MB
Errors detected..................: 0
Warnings detected................: 3 -
Understanding row_number() and using it in an analytic function
Dear all;
I have been playing around with row_number and trying to understand how to use it and yet I still cant figure it out...
I have the following code below
create table Employee(
ID VARCHAR2(4 BYTE) NOT NULL,
First_Name VARCHAR2(10 BYTE),
Last_Name VARCHAR2(10 BYTE),
Start_Date DATE,
End_Date DATE,
Salary Number(8,2),
City VARCHAR2(10 BYTE),
Description VARCHAR2(15 BYTE)
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values ('01','Jason', 'Martin', to_date('19960725','YYYYMMDD'), to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto', 'Programmer');
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('02','Alison', 'Mathews', to_date('19760321','YYYYMMDD'), to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver','Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('03','James', 'Smith', to_date('19781212','YYYYMMDD'), to_date('19900315','YYYYMMDD'), 6544.78, 'Vancouver','Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('04','Celia', 'Rice', to_date('19821024','YYYYMMDD'), to_date('19990421','YYYYMMDD'), 2344.78, 'Vancouver','Manager')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('05','Robert', 'Black', to_date('19840115','YYYYMMDD'), to_date('19980808','YYYYMMDD'), 2334.78, 'Vancouver','Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('06','Linda', 'Green', to_date('19870730','YYYYMMDD'), to_date('19960104','YYYYMMDD'), 4322.78,'New York', 'Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('07','David', 'Larry', to_date('19901231','YYYYMMDD'), to_date('19980212','YYYYMMDD'), 7897.78,'New York', 'Manager')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('08','James', 'Cat', to_date('19960917','YYYYMMDD'), to_date('20020415','YYYYMMDD'), 1232.78,'Vancouver', 'Tester')I did a simple select statement
select * from Employee e
and it returns this below
ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY DESCRIPTION
01 Jason Martin 25-JUL-96 25-JUL-06 1234.56 Toronto Programmer
02 Alison Mathews 21-MAR-76 21-FEB-86 6661.78 Vancouver Tester
03 James Smith 12-DEC-78 15-MAR-90 6544.78 Vancouver Tester
04 Celia Rice 24-OCT-82 21-APR-99 2344.78 Vancouver Manager
05 Robert Black 15-JAN-84 08-AUG-98 2334.78 Vancouver Tester
06 Linda Green 30-JUL-87 04-JAN-96 4322.78 New York Tester
07 David Larry 31-DEC-90 12-FEB-98 7897.78 New York Manager
08 James Cat 17-SEP-96 15-APR-02 1232.78 Vancouver TesterI wrote another select statement with row_number. see below
SELECT first_name, last_name, salary, city, description, id,
ROW_NUMBER() OVER(PARTITION BY description ORDER BY city desc) "Test#"
FROM employee
and I get this result
First_name last_name Salary City Description ID Test#
Celina Rice 2344.78 Vancouver Manager 04 1
David Larry 7897.78 New York Manager 07 2
Jason Martin 1234.56 Toronto Programmer 01 1
Alison Mathews 6661.78 Vancouver Tester 02 1
James Cat 1232.78 Vancouver Tester 08 2
Robert Black 2334.78 Vancouver Tester 05 3
James Smith 6544.78 Vancouver Tester 03 4
Linda Green 4322.78 New York Tester 06 5
I understand the partition by which means basically for each associated group a unique number wiill be assigned for that row, so in this case since tester is one group, manager is another group, and programmer is another group then tester gets its own unique number for each row, manager as well and etc.What is throwing me off is the order by and how this numbering are assigned. why is
1 assigned to Alison Mathews for the tester group and 2 assigned to James Cat and 3 assigned Robert Black
I apologize if this is a stupid question, i have tried reading about it online and looking at the oracle documentation but that still dont fully understand why.user13328581 wrote:
understanding row_number() and using it in an analytic functionROW_NUMBER () IS an analytic fucntion. Are you trying to use the results of ROW_NUMBER in another analytic function? If so, you need a sub-query. Analuytic functions can't be nested within other analytic functions.
...I have the following code below
... I did a simple select statementThanks for posting all that! It's really helpful.
... and I get this result
First_name last_name Salary City Description ID Test#
Celina Rice 2344.78 Vancouver Manager 04 1
David Larry 7897.78 New York Manager 07 2
Jason Martin 1234.56 Toronto Programmer 01 1
Alison Mathews 6661.78 Vancouver Tester 02 1
James Cat 1232.78 Vancouver Tester 08 2
Robert Black 2334.78 Vancouver Tester 05 3
James Smith 6544.78 Vancouver Tester 03 4
Linda Green 4322.78 New York Tester 06 5... What is throwing me off is the order by and how this numbering are assigned. why is
1 assigned to Alison Mathews for the tester group and 2 assigned to James Cat and 3 assigned Robert Black That's determined by the analytic ORDER BY clause. Yiou said "ORDER BY city desc", so a row where city='Vancouver' will get a lower namber than one where city='New York', since 'Vancouver' comes after 'New York' in alphabetic order.
If you have several rows that all have the same city, then you can be sure that ROW_NUMBER will assign them consecutive numbers, but it's arbitrary which one of them will be lowest and which highest. For example, you have 5 'Tester's: 4 from Vancouver and 1 from New York. There's no particular reason why the one with first_name='Alison' got assinge 1, and 'James' got #2. If you run the same query again, without changing the table at all, then 'Robert' might be #1. It's certain that the 4 Vancouver rows will be assigned numbers 1 through 4, but there's no way of telling which of those 4 rows will get which of those 4 numbers.
Similar to a query's ORDER BY clause, the analytic ORDER BY clause can have two or more expressions. The N-th one will only be considered if there was a tie for all (N-1) earlier ones. For example "ORDER BY city DESC, last_name, first_name" would mena 'Vancouver' comes before 'New York', but, if multiple rows all have city='Vancouver', last_name would determine the order: 'Black' would get a lower number than 'Cat'. If you had multiple rows with city='Vancouver' and last_name='Black', then the order would be determined by first_name. -
how to ignore nulls in analytic functions ( row_number() and count())
Iam attaching test data can any one help me please
thanks in advanceeeee
CREATE TABLE TEMP_table
ACCTNUM NUMBER,
l_DATE TIMESTAMP(3),
CODE VARCHAR2(35 BYTE),
VENDOR VARCHAR2(35 BYTE)
insert into temp_table values (1,sysdate+1/60,'bso','v1');
insert into temp_table values (1,sysdate+2/60,'bsof','v1');
insert into temp_table values (1,sysdate+3/60,'bsof','v2');
insert into temp_table values (1,sysdate+4/60,'','v1');
ian executing this my ;
SELECT acctnum,l_date,vendor,code_1,
CASE
WHEN code = 'bsof'
AND COUNT (DISTINCT code) OVER (PARTITION BY acctnum, vendor) > 1
AND row_number () OVER (PARTITION BY acctnum, vendor ORDER BY vendor, l_date) != 1
THEN 'yes'
ELSE 'no' END result
FROM (select acctnum,l_date,vendor, code code_1, case when code IN ('bso', 'bsof') then code
else null end code from TEMP_TABLE
ORDER BY acctnum ,l_date);
my result :
1 3/23/2011 5:24:34.000 PM v1 bso no
1 3/23/2011 5:48:36.000 PM v1 bsof yes
1 3/23/2011 6:36:41.000 PM v1 bsof yes
1 3/24/2011 11:55:53.000 AM v1 no
1 3/23/2011 6:12:38.000 PM v2 bsof no
I need to eliminate nulls in top query not in inner query (not using where condition in inner query)
[\code] -
Database Listing And Paging With Flash Builder
Hello ;
i trying to develop an android application with flash builder.
i have a database and connected it, selected a table and created a service.
my table have a four coloumn. id - img - tag - date
id : as you know. table id coloumn auto increment.
img : long text area. i want to listed to page when clicking the menu item.
tag : tag is title of the img.
date : standart date coloumn.
i want to listing all data with menu style. i added to spinner list and it get to value at database tag (title) .
how can i listing to text (long text area) in to the img coloumn when selected the tag (title) at spinner list.
thanks
bye.i researched a many document but still can't find a insert data grid.
it seems to under Components Panel all documents and videos
but i can't see it?
Anirudh SasikumarRangoraTodd_KoprivaJason San JoseSunilAdobeAmy_WongDatabase Listing And Paging With Flash BuilderUsing Flash BuilderFlex
somebody help me please?
thanks
bye -
Paging over phones and paging horns in CME
Hi all!
Cisco CME provides mechanisms for paging across phones with ephone-dn configurations, and paging across external paging systems that are connected to either FXS or FXO ports via dial-peer configurations. I have done these numerous times.
Recently I've been receiving requests to be able to dial a single paging extension and have the page go out across the phones and the horns/paging controller simultaneously. Has anyone been able to do this, and would you share the info please?
Thanks in advance,
KevinHi,
As per the doc that i shared "InformaCast has no special requirements for how multicast is enabled, and you should use your network vendor’s best practices and design considerations. Multicast is typically routed with Protocol Independent Multicast (PIM) that is deployed in either sparse or dense mode. InformaCast will work with either mode.
For WAN links where your circuit provider will not route your multicast, you can configure GRE tunnels, which carry your multicast traffic from the location where the InformaCast server is located to its recipients. The only traffic that needs to traverse these GRE tunnels is the multicast traffic you might want to route. The tunnels do not need to create a full mesh between sites; they only need to be configured from the hub location to the spoke location(s). Please see the following link for details:
http://www.cisco.com/en/US/tech/tk828/technologies_configuration_example09186a00801a5aa2.shtml
For recipients to receive the audio portion of InformaCast broadcasts, they make requests using Internet Group Management Protocol (IGMP). While most networks default to IGMPv2, newer recipients may use IGMPv3. If newer recipients are being deployed, be sure to enable the newer protocol version on network devices."
HTH
Manish -
How do we keep items in the LCDS data services cache independent between user sessions? If I use session in the destination, I can still update an item in one users cache and have it change another users item (if the identity attribute is the same).
Another way to look at this question is that we want to use the data management services to enable dynamic loading and paging of large sets of data. We don't want to utilize it for data management between sessions.
Thanks.
tjHave you seen the part of the example configs where it talks
about what is required for data paging to work?
<!--
Indicates whether data paging is enabled for the destination
and if you wish to override the
pageSize set for the channel.
Setting the custom flag to true indicates that the
associated assembler has a paged-fill method
corresponding to each method specified via the
<fill-mathod> tag. The paged-fill method
should have two additional java.lang.Integer params at the
end of the parameters specified
via the <params> tag. The first param specifes the
index in the fill collection from which this
method will start retrieving records. And the second param
specifies the number of records to be
retrieved by each paged-fill call.
Default enabled value is false. Default pageSize value is
10. Default custom value is false.
<paging enabled="true" pageSize="5" custom="true"/>
-->
It seems to imply to me that you need the paged fill methods
in your config in addition to the regular ones.
I admit I have not got as far as getting a working paging
setup yet, although this is something I will need to get working in
the near future. -
Hi,
i have the following doubts regarding the jdbc and paging please clarify me...
1)Is it advisable to use stored procedure to implement paging is records
are more in database
2)If the records are more in the database and we execute
select * from table where id >10 and id<15 then will
the query execution will be slow because the database is large(and so stored procedure will be faster)
or as we are selecting only records between 10 and 15 so the
query execution is not slow
3)will the recordset help in solving the probem
4)is there a way to select the count of the records along with the records for display in the page
the count of the records is required to display the next button
if two queries are to be written one to display the next button and second to get the records to
display on the page then the system may be slow when many users are accessing and using stored
procedures may be better
5)when we write the select query with 'for update' clause then the row will be locked
or the table is locked .
6)when we write the select query with 'for update' clause then until we execute the update
query the lock will be there and the lock will be released on executing the update query
is that right then what about the case if after the select query we get some exception
and code does not reach the update query then what about the lock will be lock remain
and give problem
regards
Javid1) that would really depend on you goals. for performance only, stored procedures are precompiled so should be faster.
2) definitely you should only select what you want and limiting the number of rows you return will speed up your query.
3) what do you mean by that? a recordset represents the collection of rows returned from the query so should help you.
4) it depends on your database. for instance, MySQL has a function to return the number of rows returned. however, some database has an unbuffered mode so that the first few rows will be returned very quickly without knowing how many rows are there, in which case, you won't know the number of rows until all the rows have been retrieved.
5 and 6 are database-dependent, while most rdbms only lock the selected rows by default, some lock the entire table.
Java 2 MVP
http://www.brainbench.com -
ROW_NUMBER() and CONTAINS()
Hello,
I'm having a bit of bother with a view that uses ROW_NUMBER() and a query that uses CONTAINS().
I have a table A (A INTEGER, B VARCHAR2) and view V_A:
SELECT A, B, ROW_NUMBER() OVER (ORDER BY A) N
If I execute a query
SELECT * FROM V_A WHERE CONTAINS(B, 'X')>0
it doesn't matter what I put in X. The query simply ignores the CONTAINS()>0 clause.
Does anybody know why this might be and if it is possible to fix it?
Thanks!CONTAINS() works well if I remove ROW_NUMBER() from the view. How did you define the index?
I seem not even to be able to query a simple view using the contains operator (I am on 11g):
SQL> create table emp_test as select * from emp
Table created.
SQL> create or replace view v_emp_test as select * from emp
View created.
SQL> create index emp_test_txt on emp_test (ename) indextype is ctxsys.context
Index created.
SQL> select * from emp_test where contains (ename,'SC%') > 0
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
1 row selected.
SQL> select * from v_emp_test where contains (ename,'SC%') > 0
Error at line 0
ORA-20000: Oracle Text error:
DRG-10599: column is not indexed -
Difference between swap-ing and paging
I wander what is difference between swap-ing and paging. What are pages-out and what are pages in(in transaction st06)
HI
The following link may also be useful.
http://learnlinux.tsf.org.za/courses/build/internals/ch05s03.html
Regards
Chen -
ROW_NUMBER() and complex expression of ORDER BY
Hi everybody,
I am getting confused and can not figure out how to incorporate different sort order (ASC or DESC) into this complex expression. I can possible do this using IF /ELSE construct but I am not sure I like it.
I am re-writing the stored procedure I wrote 2 weeks ago to incorporate server side paging rather than client site. I have ng-grid working fine and filtering / paging quite quickly client side, but an account can have 400,000 invoices and sending all of
this to the client doesn't seem right.
So, this is what I wrote so far and I am confused as how to add asc/desc order into that procedure:
ALTER PROCEDURE dbo.siriussp_GetAccountInvoices
(@acctName CHAR(10),
@Finalized BIT = 0,
@PageSize INT = 15,
@PageNumber INT = 1,
@SearchText VARCHAR(max) = '',
@OrderBy VARCHAR(20) = '',
@SortOrder VARCHAR(4) = 'ASC',
@TotalRows INT OUTPUT)
AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID('TempDb..#AccountInvoices', N'U') IS NOT NULL DROP TABLE #AccountInvoices;
SELECT i.invoice_no, i.descrip1 as Descrip, i.hidden, i.finalized, i.date_time as Created,
COALESCE(Bal.Balance,0) as Balance, ROW_NUMBER() OVER (ORDER BY
CASE WHEN @OrderBy ='InvoiceNo' OR @OrderBy = '' THEN i.invoice_no END,
CASE WHEN @OrderBy = 'Descrip' THEN i.descrip1 END,
CASE WHEN @OrderBy = 'Balance' THEN Bal.Balance END,
CASE WHEN @OrderBy = 'Created' THEN i.date_time END) AS Rn
INTO #AccountInvoices
FROM dbo.invoices i
OUTER APPLY (SELECT SUM(extension) as Balance FROM dbo.transact t
WHERE t.invoice_no = i.invoice_no) Bal
WHERE i.account = @acctName
AND (@Finalized = 0 OR (@Finalized = 1 and i.finalized = 1))
AND (@SearchText = '' OR (CAST(i.invoice_no AS VARCHAR(17)) LIKE @SearchText + '%' OR i.descrip1 LIKE '%' + @SearchText + '%'
OR CAST(Bal.Balance AS VARCHAR(20)) LIKE @SearchText + '%'))
OPTION (RECOMPILE);
SET @TotalRows = @@ROWCOUNT;
SELECT * FROM #AccountInvoices WHERE Rn >= (@PageNumber-1) * @PageSize AND Rn < @PageNumber * @PageSize
ORDER BY Rn;
END
Thanks in advance.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articlesI like that, quite creative.
My current procedure is simple enough, I think, although I am not sure that using temp table is a very good idea, but I don't see lots of alternatives. One account can have up to 400000 (or more) invoices for big clients. My current test database only has
28 invoices per account (it's a maximum). I would also want to somehow figure an approach of doing client vs. server side paging on the fly (depending on total numbers) as it seems a bit silly to go to the server for next 15 rows while we have only 30 in total.
That (applying 2 separate approaches on the fly) will be a challenge in itself.
Anyway, here is my current procedure and I'd welcome advices of improving it. The client side filtering right now applies 'contains' filter against all 4 columns but I think it's wrong and we better use filter for only 3 columns (excluding the date column)
and use starts with for the invoice number or balance rather than include.
ALTER PROCEDURE dbo.siriussp_GetAccountInvoicesWithPaging
(@acctName CHAR(10),
@Finalized BIT = 0,
@PageSize INT = 15,
@PageNumber INT = 1,
@SearchText VARCHAR(max) = '',
@OrderByColumn VARCHAR(20) = '',
@SortOrder VARCHAR(4) = 'ASC',
@TotalRows INT OUTPUT)
AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID('TempDb..#AccountInvoices', N'U') IS NOT NULL DROP TABLE #AccountInvoices;
CREATE TABLE #AccountInvoices (invoice_no numeric(17,0) NOT NULL,
Descrip VARCHAR(25) COLLATE DATABASE_DEFAULT NOT NULL,
hidden BIT NOT NULL, finalized BIT NOT NULL, Created DATETIME NULL,
Balance MONEY, Rn Int)
DECLARE @Sql NVARCHAR(MAX);
SET @Sql = 'SELECT i.invoice_no, i.descrip1 as Descrip, i.hidden, i.finalized, i.date_time as Created,
COALESCE(Bal.Balance,0) as Balance, ROW_NUMBER() OVER (ORDER BY ' +
CASE WHEN @OrderByColumn ='InvoiceNo' OR @OrderByColumn = '' THEN 'i.invoice_no'
WHEN @OrderByColumn = 'Descrip' THEN 'i.descrip1'
WHEN @OrderByColumn = 'Balance' THEN 'Bal.Balance'
WHEN @OrderByColumn = 'Created' THEN 'i.date_time' END
+ CASE WHEN @SortOrder = 'DESC' THEN ' DESC' ELSE '' END + ') AS Rn
FROM dbo.invoices i
OUTER APPLY (SELECT SUM(extension) as Balance FROM dbo.transact t
WHERE t.invoice_no = i.invoice_no) Bal
WHERE i.account = @acctName ' +
CASE WHEN @Finalized = 0 THEN '' ELSE ' AND i.finalized = 1' END +
CASE WHEN @SearchText = '' THEN '' ELSE ' AND (CAST(i.invoice_no AS VARCHAR(17)) LIKE @SearchText + ''%''
OR i.descrip1 LIKE ''%'' + @SearchText + ''%''
OR CAST(Bal.Balance AS VARCHAR(20)) LIKE @SearchText + ''%'')' END;
PRINT @SQL;
INSERT INTO #AccountInvoices (invoice_no, Descrip, hidden, finalized, Created, Balance, Rn)
EXECUTE sp_executeSQL @Sql, N'@acctName CHAR(10), @SearchText VARCHAR(max)', @acctName = @acctName, @SearchText = @SearchText;
SET @TotalRows = @@ROWCOUNT;
SELECT * FROM #AccountInvoices WHERE Rn >= (@PageNumber-1) * @PageSize AND Rn < @PageNumber * @PageSize
ORDER BY Rn;
END
/* Test
DECLARE @TotalRows INT = 0
execute dbo.siriussp_GetAccountInvoicesWithPaging @acctName = '*GUESTS*', @Finalized = 0,
@TotalRows = @TotalRows OUTPUT, @SearchText = '', @SortOrder = 'DESC', @OrderByColumn = 'Balance'
SELECT @TotalRows
Hmm, I thought I commented out print @SQL, but apparently I didn't.
I am also thinking I'd add a check for ISNUMERIC(@Search) because otherwise there is no need to compare balances and invoices.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
I know in SAP's world, memory means physical memory + paging. I want to know which program has contribution for swap.
Suppose there is 4G physical memory on an application server, em/initial_size_MB = 4G, abap/heap_area_nondia = 4G.
1) If there is no dialog processor running and one background job running which claims 2G memory, I want to know will swap occur?
2) If there is one dialog processor running which claims 2G memory and one background job running which claims 2G memory, will swap occur?By ST03N you can check the workload, by OS06 the swap .
By transaction ST02 you can check the folllowing parameters:
SAP Roll area parameters
- ztta/roll_first : First amount of roll area used in a dialog WP
- ztta/roll_area : size of the local SAP Roll area in the work process
rdisp/ROLL_SHM : size of SAP roll Buffer
rdisp/ROLL_MAXFS : size of entire shared SAP roll area
SAP Extended Memory main parameters :
em/initial_size_MB : size of SAP extended memory allocated when the SAP instance starts up
em/blocksize_KB : size block which split SAP Extended Memory
ztta/roll_extension : maximum size of a user context in the SAP Extended memory
SAP Heap Memory main parameters :
abap/heap_area_dia : quotas oh SAP heap memory that a dialog process can allocated.
abap/heap_area_nondia : quotas oh SAP heap memory that a nondialog process can allocated.
abap/heap_area_total : size that can be allocated in total by all work process.
abap/heaplimit : Workprocess restart limit of heap memory
if helpful reward point is appreciated -
Search Results Web Part, Managed Navigation and Paging
I am using managed navigation and have a search results web part that uses the Term.IdWithChildren as the query to filter the results by the selected navigation term. This works nicely until you need to us the paging. As soon as you go to the next page there are
no results.
It would appear that as soon as the URL has the #k=#s=11 added it looses the navigation term. This is a core part of the Sharepoint solution that I'm delivering and I cannot progress this any further and I'm going round in circles. I have another results
page that has the search results webpart on but doesn't use the navigation term filtering and the paging works fine.
As an alternative I was looking at writing my own search results web part, can I do this and render the sharepoint display templates somehow?
Any help would be appreciated.
StuartHi Stuart,
i suppose you may need to check your design regarding this custom coding,
as i know, when i tried previously, i didn't take any attention on the query result, so that it appear as no result.
please have a check this links, it helped me once,
http://technet.microsoft.com/en-us/library/gg549981.aspx
http://social.technet.microsoft.com/Forums/sharepoint/en-US/59e6e258-294d-44b2-996a-547e4e9f519d/customize-search-statistics-and-search-paging-web-parts
http://kamilmka.wordpress.com/2012/04/14/customize-sharepoint-search-results-paging/http://blogs.msdn.com/b/sanjaynarang/archive/2009/02/20/handling-paging-and-total-results-count-in-sharepoint-custom-results-page.aspx
Regards,
Aries
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. -
ROWNUM, Cursor, and Paged Reports
I am using ASP against a Oracle 8i DB in a web application. I have some large reports (approx 2,000 records) that I need to display on the site in a paged style report. i.e. 25 records on page 1, 26-50 on page 2, etc...... Much like you see here at OTN in the forums.
The problem is that when I go through the the ADO to build my recordset against the DB, I need to be able to select just a certain set of rownumbers. I will also need to be able to reorder the report based on client response. I know that the ROWNUM psudeofield is filled before any sort criteria is applied through the order by clause. So if I select against the view, how will I tell it to give me the next set of records that will make up my page. A oracle book I have says to use the cursor object to do this, but I am not really familiar with that, and from what I can see, it still didn't tell me how to select just a small part of the overall recordset that might be returned to the cursor by the SQL statement.
Does any of this make sense? And if so, can someone please point me to a good source of information on how to do this. I know it has to be possible, becuase sites have that ability all over the place, but as I might be changing from ASP to JSP soon, I don't really want to do it all in code,becuase then I have to rewrite that as well. Doing this on the database is really my only good option.Here is an example, that uses the Oracle emp demo table to demonstrate how to use a ref cursor to return a result set ordered by whatever columns you want and get any set of rows you want. In the example, I first ordered by the empno column and retrieved the first 10 rows, then the next set of 10 rows (there are only 14 rows, so it just displays 4 more rows). Then I ordered by the ename column and retrieved 5 rows at a time. You can specify any number or combination of columns and any starting or ending rows you want.
SQL> CREATE OR REPLACE PACKAGE package_name
2 AS
3 TYPE cursor_type IS REF CURSOR;
4 PROCEDURE procedure_name
5 (p_result_set IN OUT cursor_type,
6 p_order_by IN VARCHAR2,
7 p_start_row IN NUMBER,
8 p_end_row IN NUMBER);
9 END package_name;
10 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY package_name
2 AS
3 PROCEDURE procedure_name
4 (p_result_set IN OUT cursor_type,
5 p_order_by IN VARCHAR2,
6 p_start_row IN NUMBER,
7 p_end_row IN NUMBER)
8 IS
9 v_sql VARCHAR2 (4000);
10 BEGIN
11 v_sql :=
12 'SELECT *'
13 || ' FROM (SELECT ROWNUM AS r, a.*'
14 || ' FROM (SELECT * '
15 || ' FROM emp'
16 || ' ORDER BY ' || p_order_by || ') a'
17 || ' WHERE ROWNUM <= :p_end_row )'
18 || ' WHERE r >= :p_start_row';
19 OPEN p_result_set FOR v_sql USING p_end_row, p_start_row;
20 END procedure_name;
21 END package_name;
22 /
Package body created.
SQL> SET LINESIZE 125
SQL> VARIABLE g_ref REFCURSOR
SQL> -- to get first ten rows ordered by empno:
SQL> EXEC package_name.procedure_name (:g_ref, 'EMPNO', 1, 10)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
1 7369 SMITH CLERK 7902 17-DEC-80 800 20
2 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
3 7521 WARD SALESMAN 7698 22-FEB-81 1250 505.07 30
4 7566 JONES MANAGER 7839 02-APR-81 2975 20
5 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
6 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7 7782 CLARK MANAGER 7839 09-JUN-81 2450 10
8 7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
9 7839 KING PRESIDENT 17-NOV-81 5000 10
10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
10 rows selected.
SQL> -- to get second ten rows ordered by empno:
SQL> EXEC package_name.procedure_name (:g_ref, 'EMPNO', 11, 20)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
11 7876 ADAMS CLERK 7788 12-JAN-83 1100 20
12 7900 JAMES CLERK 7698 03-DEC-81 950 30
13 7902 FORD ANALYST 7566 03-DEC-81 3000 20
14 7934 MILLER CLERK 7782 23-JAN-82 1300 10
SQL> -- to get first five rows ordered by ename:
SQL> EXEC package_name.procedure_name (:g_ref, 'ENAME', 1, 5)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
1 7876 ADAMS CLERK 7788 12-JAN-83 1100 20
2 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
3 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
4 7782 CLARK MANAGER 7839 09-JUN-81 2450 10
5 7902 FORD ANALYST 7566 03-DEC-81 3000 20
SQL> -- to get second five rows ordered by ename:
SQL> EXEC package_name.procedure_name (:g_ref, 'ENAME', 6, 10)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
6 7900 JAMES CLERK 7698 03-DEC-81 950 30
7 7566 JONES MANAGER 7839 02-APR-81 2975 20
8 7839 KING PRESIDENT 17-NOV-81 5000 10
9 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
10 7934 MILLER CLERK 7782 23-JAN-82 1300 10
SQL> -- to get third set of five rows ordered by ename:
SQL> EXEC package_name.procedure_name (:g_ref, 'ENAME', 11, 15)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
11 7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
12 7369 SMITH CLERK 7902 17-DEC-80 800 20
13 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
14 7521 WARD SALESMAN 7698 22-FEB-81 1250 505.07 30 -
Hello everybody,
First, excuse me for the mistakes I may have made.
I am a trainee and the enterprise I work for is planning to
change the presentation layer (and maybe all the layers) of their
software packages for Flex (at the present time they use the .NET
platform). But in order to ensure that Flex can answer their needs,
they have asked me to make a model using Flex together with Java,
Hibernate, LCDS, SQL Server and Tomcat.
I am currently using those versions :
- jdk 1.5.0_12
- Hibernate 3 (I use the jars provided with LCDS)
- LCDS 2.5
- SQL Server 2005
- Tomcat 5.5
As far as some of the tables from their databases are quite
big (they can reach 2.000.000 rows) I need to implement paging. The
table I currently use for my example is "only" 10.000 rows.
I must confess that I am new to n-tiers architectures and
that there are many concepts I misunderstand.
What I want to do is make the user able to choose how many
rows a page he wants to display (This could look a bit like
this). And
the server would only send this number of rows for each page (which
is not the case for the page I linked).
I have noticed that the implementation of the fill method for
the HibernateAssembler had changed between FDS (
public Collection fill(List fillArgs)) and LCDS (
public Collection fill(List fillArgs, int startIndex, int
numItems)).
You are now able to specify a start index and the number of
rows to display. This is the method I would like to use.
To do so, I have tried to refer to
LCDS
documentation but I find it quite confusing. Here it is :
Using on-demand paging
There are two ways in which the Data Management Service
implements on-demand paging of data by Flex clients. In the default
approach, the fill method returns the entire collection of objects.
The server sends the first page of items to the client as part of
the initial fill request.
As the client code tries to access ArrayCollection elements
which are not resident, additional pages are retrieved from the
server. If the cache-items property is set to true, these pages are
sent directly by the Data Management Service. If the cache-items
property is set to false, the Data Management Service calls the
getItem() method for each item it needs to send to the client.
When the original query is too large to be held in the
server's memory, it is desirable for the Assembler to only return a
single page of items at a time. In this mode, each time the client
requests a page, the Assembler is asked for that page of items and
they are sent directly to the client. Currently this mode is not
supported when the autoSyncEnabled property is set to true for the
paged collection. You must set the autoSyncEnabled property to
false before executing the code. This configuration is not
supported for the SQLAssembler. It is supported for the
HibernateAssembler and you can implement it with your own Java
Assembler implementation.
To enable this second mode, you set the custom="true"
attribute on the paging element in your network settings on the
server and ensure paging is enabled with a reasonable pageSize
value.
If you are using the fill-method approach in your Assembler,
you specify a fill method that matches the fill parameters used by
your client with two additional parameters: the startIndex and the
number of items requested. The Data Management Service calls this
method once for each page requested by the client.
If you are using the Assembler interface approach, you
override the useFillPage() method for the appropriate fill method
to return true for the fill parameters you want paged using custom
paging. When the client requests a page, it calls the fill variant
in the Assembler interface which takes the additional startIndex
and number of items parameters. You return
just those items and they are returned to the client.
When you use custom paging in either the fill-method or
Assembler approach, there are two ways that the client can
determine the size of the collection. When you have enabled the
custom paging mode, on the initial fill request made by the client,
the Data Management Service invokes the count method with the
parameters the client passed to fill. If the count
method returns -1, a dynamic sizing algorithm is used for
this filled collection. In this approach, the assembler's paged
fill method is called with startIndex of 0 and number of items set
to the pageSize + 1. If the assembler method returns less than the
number requested, the size of the fill is known. If it returns the
pageSize+1 items requested, pageSize items are
returned to the client but the client sets the collection
size to pageSize + 1 - with one empty slot at the end. When that
empty item is requested by the client, the next pageSize+1 items
are requested and the process repeats until the assembler returns
less than pageSize+1 items.
The HibernateAssembler implements this dynamic paging
mechanism when you set the page-queries-from-database attribute to
true in the destination's server properties. If you are using an
HQL query sent from the client and the query is a simple query, the
Hibernate assembler attempts to implement a count query by
modifying the query sent from the client.
If you are using a named query, the Hibernate assembler looks
for a query named <original-query-name>.count. If that query
exists, it uses it to compute the size of the paged collection.
Otherwise, it uses the dynamic-sized approach.
I guess I should change
<params>java.util.List</params> for
<params>java.util.List,int,int</params>.
But I don't know which properties to add or modify.
It also talks about the custom attribute of the paging
element. Is it a new attribute that replaces "enabled" ? Or does it
come in addition to it ?
The following files are working and allow me to retrieve the
datas I expect (but without paging).
My data-management-config.xml looks like this :
<?xml version="1.0" encoding="UTF-8"?>
<service id="data-service" class="flex.data.DataService"
messageTypes="flex.data.messages.DataMessage">
<adapters>
....<adapter-definition id="java-adapter"
class="flex.data.adapters.JavaAdapter" default="true"/>
</adapters>
<default-channels>
....<channel ref="my-rtmp"/>
</default-channels>
<destination id="refacteur.hibernate">
....<adapter ref="java-adapter" />
....<properties>
........<use-transactions>true</use-transactions>
........<source>flex.data.assemblers.HibernateAssembler</source>
........<scope>application</scope>
........<metadata>
............<identity property="cleacteur"/>
........</metadata>
........<network>
............<session-timeout>20</session-timeout>
............<paging enabled="false" pageSize="20"/>
............<throttle-inbound policy="ERROR"
max-frequency="500"/>
............<throttle-outbound policy="REPLACE"
max-frequency="500"/>
........</network>
........<server>
............<hibernate-entity>fr.phylum.referentiel.Refacteur</hibernate-entity>
............<fill-method>
................<name>fill</name>
................<params>java.util.List</params>
............</fill-method>
............<fill-configuration>
................<use-query-cache>true</use-query-cache>
................<allow-hql-queries>true</allow-hql-queries>
............</fill-configuration>
........</server>
....</properties>
</destination>
</service>
This is the named query definition I use, found in
Refacteur.hbm.xml :
<query name="refacteur.where.ville.order.by.libacteur">
....<![CDATA[
........from Refacteur as refacteur
........where refacteur.villeActeur = ?
........order by libacteur
....]]>
</query>
And here is the call to the fill method, found in my mxml
application file Acteurs.mxml :
globalFilter.dataService.fill(globalFilter.arrayCollection,
"refacteur.where.ville.order.by.libacteur", ["VANNES"]);
I have tried to modify several things, but nothing works.
I would be most grateful if someone could tell me what to
change in my files in order to make the paging work.
Nathalie.Have you seen the part of the example configs where it talks
about what is required for data paging to work?
<!--
Indicates whether data paging is enabled for the destination
and if you wish to override the
pageSize set for the channel.
Setting the custom flag to true indicates that the
associated assembler has a paged-fill method
corresponding to each method specified via the
<fill-mathod> tag. The paged-fill method
should have two additional java.lang.Integer params at the
end of the parameters specified
via the <params> tag. The first param specifes the
index in the fill collection from which this
method will start retrieving records. And the second param
specifies the number of records to be
retrieved by each paged-fill call.
Default enabled value is false. Default pageSize value is
10. Default custom value is false.
<paging enabled="true" pageSize="5" custom="true"/>
-->
It seems to imply to me that you need the paged fill methods
in your config in addition to the regular ones.
I admit I have not got as far as getting a working paging
setup yet, although this is something I will need to get working in
the near future.
Maybe you are looking for
-
I exported my 1920x1080 ProRes HQ sequence as a Quicktime movie (using Export>QT Movie, Use current settings, make self-contained) Takes about 30 minutes to export the 95 minute show, but when I bring it back into FCP I get the error that the clip is
-
How can i get help by Administrator online.
All Administrator off-line, I cannot get help from the Administrator. I am really urgent !
-
RAW (NEF) files from Nikon D3200
I previously had a D3000 and was able to open NEF files in Elements 9 with ACR. Now, Having upgrade to a D3200, Elements 9 won't open or even recognise the NEF files. I have contacted Nikon, but they say that the files from the D3200 are 'not compati
-
DoScript VBScript to VBScript?
I would like to have serveral common VBScripts that are run by different VBScripts. Would the DoScript command be the correct choice to do this? Below is a script that I'm working on that has several Functions. I would like to put each Function in a
-
Hi, Really just want to know, I have this task to develop a sime web app that involves a database (to add new records, retrieve data, del, perform queries etc), where there are a number of user access levels. I'm envisioning that users will perform a