Get the record count

The Query below is part of a huge query. The snipet is just the part that I need to make a change.
For the query below, how can I get the recordcount in the select inside the case statement? I want to only output the r_text when the record count of the select is zero (0) else make the output to r_text null
select
distinct a.style_id, b.sty, b.season, a.cust, a.ad_d, b.code,
(case when b.code = 'MAKE' then
(select min(t.value) from sn.age r, sn.text t
where r.t_id = '18' and r.name = 'MTGNSL'
     and r.t_id = t.t_id
     and r.name = t.name and r.text_id = t.text_id
     and r.id_1 = a.id
) end) r_text,
(case when b.code is null then 'Blank Code'
when b.code = 'MAKE' then 'MAKE' end) err
     

If you are not using a scrollable result set then the following is the best way to do it.
there are several key words in SQL that can be used, the one you are interested in is count();
so if your query at the moment is
"select col1, col2, col3 from my_table where col2=? and col3=?"you can work out how many rows will be returned by executing this command first
"select count(col1) from my_table where col2=? and col3=?"this will return a result set with one row and one column, you can get the row count as follows:
ResultSet rs = ps.executeQuery();
int rowCount = rs.getInt(1);I hope this helps :)

Similar Messages

  • How to get the record count printed for the report in the Dashboards

    Hi,
    I would like to get the record count printed at the bottom of every dashboard report like:
    < 1 - 25 of 6300 > instead of < 1 - 25 >
    Any help is appreciated
    Regards
    B

    I have tried the following formula which identifies the lowest grain but it does not seem to give me correct result.. I am not getting the correct count. I am getting as 3.A work order can be updated only once at one point of time.hence the formula
    MAX(RCOUNT(CAST("SR Wo Fact"."Crm Wo Number" AS CHAR) ||CAST("SR Wo Fact"."PSC Timestamp" as char)))
    I tried only MAX(RCOUNT(1)), but I was able to get the record count as corect for Administrator but not for other users.
    Has anyone come across this scenario.
    Thanks Shravan
    Edited by: 786443 on Aug 19, 2010 10:22 AM

  • Get the record count from a query

    Hi,
    does anyone know how to get the record count from a sql query?
    e.g: I've got a ResultSet from the Statement.excuteQuery(), and I want to know how many records this ResultSet contains, how to get this?
    I'd read thoughout the documents of Statement and ResultSet, but couldn't find a solution, do I have to use another seperate query such as "select count(*)" to do this?
    thanks.
    Yang Liu

    If you are not using a scrollable result set then the following is the best way to do it.
    there are several key words in SQL that can be used, the one you are interested in is count();
    so if your query at the moment is
    "select col1, col2, col3 from my_table where col2=? and col3=?"you can work out how many rows will be returned by executing this command first
    "select count(col1) from my_table where col2=? and col3=?"this will return a result set with one row and one column, you can get the row count as follows:
    ResultSet rs = ps.executeQuery();
    int rowCount = rs.getInt(1);I hope this helps :)

  • Getting the record count from result set

    i'm retreiving the result set using the executeQuery method, now i want to know how many records are there in the result set, that is the record count of the result set.
    one solution to that is to first use the executeUpdate and then use the executeQuery but i think that is not the right way.
    so please tell me is there any method in jdbc to get that thing done
    Tanx

    Hi
    Do you know if your DB supports "insensitive scrolling"?
    SQL generally do, but some don't - I had the same problem with the
    open source version of Interbase from Phoenix...
    Anyway - try creating your statement this way:
    public Statement createStatement(int resultSetType, int resultSetConcurrency)
    throws SQLException
    ...where resultset type should be:
    ResultSet.TYPE_SCROLL_INSENSITIVE
    Then you can do this:
    ResultSet rs = stm.executeQuery(q);
    int size = rs.last(); //this what you looking for?
    rs.beforeFirst();
    while(rs.next()){
    }

  • How to get the record count before fetch

    CREATE PACKAGE demo_cur_pkg AS
    TYPE EmpName IS RECORD (name VARCHAR2(10));
    TYPE cur_type IS REF CURSOR RETURN EmpName;
    PROCEDURE open_emp_cur (
    curs IN OUT cur_type,
    dept_num IN NUMBER);
    END;
    CREATE PACKAGE BODY demo_cur_pkg AS
    CREATE PROCEDURE open_emp_cur (
    curs IN OUT cur_type,
    dept_num IN NUMBER) IS
    BEGIN
    OPEN curs FOR
    SELECT ename FROM emp
    WHERE deptno = dept_num
    ORDER BY ename ASC;
    END;
    END;
    After this package has been stored, you can open the cursor curs by calling the open_emp_cur stored procedure from your Pro*C/C++ program, and FETCH from the cursor in the program. For example:
    sql_cursor emp_cursor;
    char emp_name[11];
    EXEC SQL ALLOCATE :emp_cursor; /* allocate the cursor variable */
    /* Open the cursor on the server side. */
    EXEC SQL EXECUTE
    begin
    demo_cur_pkg.open_emp_cur(:emp_cursor, :dept_num);
    end;
    EXEC SQL WHENEVER NOT FOUND DO break;
    for (;;)
    EXEC SQL FETCH :emp_cursor INTO :emp_name;
    printf("%s\n", emp_name);
    Any solutioon is welcome

    Fail to understand why you want to introduce exception processing - e.g. use methodA for less than 10,000 rows and use methodB for 10,000 and more.
    Why not use methodC - optimal support for fetching, irrespective of whether there are 1 row to fetch, or a 100,000 rows?
    There is no best way for fetching a small number of rows versus a different best way for fetching more rows. There is a single optimal method - and this remains the same irrespective of the number of rows being returned.

  • How to return the record count of a query to a number variable

    How would I get the record count from a query without using a cursor to step through the query and count the records individually?
    query: select * from table1 where column1 = column2
    How would I get the record count of the query above?
    thanks,
    michelle

    I figured it out
    select count(*) into theCount
    from ( select * from table1 where column1=column2 );
    thanks,
    michelle

  • How to get the record set into array?

    Hi,
    I want to get the record set into array in the procedure and do the processing of the array later in procedure.
    below is the stored procedure i am working on:
    procedure bulk_delete_group(p_group_id in Array_GroupListID) as
    begin
    for i in p_group_id.first..p_group_id.last loop
    --Here I have to get the list of user id before deleting group
    SELECT user_id into *<SOME ARRAY>* FROM group_members WHERE group_id = p_group_id(i);
    DELETE group WHERE group_id = p_group_id(i);
    --Process the user id array after group deletion..
    end loop;
    end bulk_delete_group;
    Thanks in advance
    Aditya

    Something like this ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.20
    satyaki>
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
          7777 SOURAV     SLS                  14-SEP-08      45000       3400         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       4450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       7000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    13 rows selected.
    Elapsed: 00:00:02.37
    satyaki>
    satyaki>create type np is table of number;
      2  /
    Type created.
    Elapsed: 00:00:03.32
    satyaki>
    satyaki>Create or Replace Procedure myProc(myArray np)
      2  is
      3    i   number(10);  
      4    rec emp%rowtype;  
      5  Begin  
      6    for i in 1..myArray.count
      7    loop  
      8      select *  
      9      into rec 
    10      from emp 
    11      where empno = myArray(i); 
    12     
    13      dbms_output.put_line('Employee No:'||rec.empno||' Name:'||rec.ename); 
    14    end loop; 
    15  End myProc;
    16  /
    Procedure created.
    Elapsed: 00:00:00.88
    satyaki>
    satyaki>
    satyaki>declare
      2    v np:=np(9999,7777);  
      3  begin  
      4    myProc(v);  
      5  end;
      6  /
    Employee No:9999 Name:SATYAKI
    Employee No:7777 Name:SOURAV
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.30
    satyaki>Regards.
    Satyaki De.

  • How to implement the record count on the page

    Dear,
    I have a basic search page, results region with a simple table.
    I need to show the total number of records returned by a search query.
    Suppose I create messageStyledText "counter" bean to show the result.
    The result will be calculated in the ProcessFormRequest, how would I set the value of the the "counter" bean then? I can not do that in PFR.
    Thank you
    Anatoliy

    In the PFR method of controller, get the row count of VO when user click on search button and then set its value in the counter bean.
    Here the dummy code.. check syntax error & other compile time error
    if(pageContext.getParameter("SearchBtn") != null)
    OAViewObject vo = (OAViewObject)am.findViewObject("SearchVO1")
    if (vo!= null)
    String fetchedRowCount = vo.getFetchedRowCount();
    OAMessageStyleTextBean msb = (OAMessageStyleTextBean)webBean.findChildRecursive("CounterBean");
    if(msb != null)
    msb.setvalue(pageContext, fetchedRowCount);
    }Thanks
    --Anil
    http://oracleanil.blogspot.com

  • What event should I use to grab the record count of a DataGrid?

    I have a "Go" button on a search form.  It works correctly, fetching records from a CF data service into a data bound DataGrid.  However, using the code shown below, the record count always shows zero.  I've tried putting the "..Provider.length" line shown below, into various events on the grid, so that it will always update the count at the correct time, but I get "null" object errors at run time. There seems to be no event that fires "AfterDataLoad".
                protected function btnGo_clickHandler(event:MouseEvent):void
                     getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
                     tabSbjs.label = 'Subjects: ' + grdSBJs.dataProvider.length;    //  This always returns zero.  Why?

    For example, this doesn't work.  The grid is told to loaded data on line 1, but this must just be only a message send to the Flash Player 10, because the processing doesn't stop and wait for the loading of data to complete, it just continues on to line 2, at which point '...Provider.length' is always zero the first time through.   So... the NEXT time the user clicks the Go button, line 2 is processed for the DataGrid which is holding data from the PREVIOUS search, so it updates the tabSbjs.label with the count from the previous search, not the current search.  The count of records is always for the previous data set.
                protected function btnGo_clickHandler(event:MouseEvent):void
    1               getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);  // edtSrch.text
    2               tabSbjs.label = 'Subjects: ' + grdSBJs.dataProvider.length;                                                                            
    All I'm trying to do is (which seems like a very difficult thing to do in FB4):
    -Display a DataGrid popluated with data records
    -Display a count of how many records are in the data grid
    If I rely on CF9 functions, which can only return a single value, then I have to make two CF9  functions, with the exact same SQL, one that returns data, and one that returns a count of the records.... which is non-sensicle.
    There must be a simple way to do this, but I'm going around in circles.

  • Get estimated record count

    for pagination, we want to show the total pages. the way is to get the total count,then divided by the record number per page. The problem is its too expensive to get the total count.
    In pl/sql, we can get the estimated record count with
    select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST')); but my question is how to get this number from application code, like java or php.
    Thanks,

    Hi,
    Though what you're trying to do can be achieved in three steps *(i)* importing of java.io.* and java.sql.* packages *(ii)* establishment of a connection using JDBC driver, and *(iii)* query execution, it would NOT be constructive for the fact that a SELECT statement (as stated in the above reply) will always be a part of the query sentence for the following reasons:
    (a) When objects are executed in Java, the first statement that is compiled is a SQL statement.
    (b) Parameters cannot be defined in SQL strings.
    Hence, as per my understanding, you can either stick to the existing approach or modify it as per the defined standards and not customized ones.
    Regards,
    Naveed.

  • How to get the column count at the bottom of the column

    Hi Friends,
    How to get the column count at the bottom of the column
    Thanks
    Raj

    You mean row count? Add another column, click on the fx button and type RCOUNT(1).
    If you want just the total you can make it MAX(RCOUNT(1)), hide this column and then add a Narrative View after your report and enter "Total Number of Records: @n" where "n" represents what order your column is from the left side.

  • File Adapter - how to get the file count from a folder

    Hi All,
    I have a requirement that have to poll a directory when the file count is reached to number N (ex:number of files avilable in folder is 5) otherwise it should wait and not pick any of the files. Is it possible to get the file count from a folder using file adapter ?? otherwise please suggest me an approach to achieve this requirement.
    Thanks,
    JJ

    Hi Sarath,
    Thank you for your reply.
    Go with the list files operation of file adapter it will gives you the number of files in the specified folder as you given. . - this step is already done.
    When the number of files reaches your count startup your webservice that which can polls the files. . . - how can i acheive this?? Have to poll the directory and process the number files - please let me know, what could be added to the webservice which is being invoked after cheking file count from parent process.
    The reason for the above question is - we cannot use ReadFile operation in second webservice because it will be automatically triggered when the file is avilable. Also SyncRead operation supports reading one file in b/w bpel process. Kindly explain me the implementation steps.
    Thanks,
    JJ

  • Unable to get the row count of supplier site for each supplier

    Hi,
    In the sourcing module, suppliers page is having an advanced table in which there is a field 'supplier' and another filed 'supplier sites' (supplier field is of type picklist).Now, how can i get the count of 'supplier sites' for each supplier???

    Hi sumit,
    Thanks for the reply, can u please help in writing the code to loop through the VO...
    I was trying to get the first row and then finding the count of supplier sites, but in each iteration of for loop(for each row) i am getting the same count value for each and every row...
    Code :
    int j=vo.getrowcount();//count of no. of rows
    for (int i=0;i<j;i++)
    row=(xxVORowImpl)rowsetiterator.getRowAtRangeIndex(1);
    int a=am.getSupplierSitesVO.getRowCount();//this is the view object in the pick list
    oapagecontext.writeDiagnostics(this,"value of   a is :"+a,1);
    this code is giving row count of last row of supplier.
    How to get the count for each and every row of supplier sites ?
    Thanks.

  • How to get the row Count of a ResultSet

    How to get the row Count of a ResultSet

    Hi
    I'v tried rennie1's way ,but I only get zero,my code is:
    rs.executeQuery("select count(*) from t_test");
    if (rs.next()) int rowCount=rs.getInt(1);
    I also tried barni's way ,but the method rs.last() and rs.beforeFirst() throw a same Exception
    I tried another way,the code is:
    while rs.next(){
    // Do nothing ,just move the cursour to the last row
    int rowCount=rs.getRow()
    However,the rowCount still equal zero
    Any help would be greatly apprecite!
    note:
    I get connection by DataSource's JNDI name from client, the Server is Weblogic Server 6, the DBMS is Oracle.

  • How to get the FILE COUNT from File directory

    Hello,
    i have to develop a scenario like, get  the file count from source file directory and validate whether the file count is 5 or not. if 5 files exist i need to process those 5 files to DB tables. if file count is not equal to 5 then i need to send a mail to customer that files are missed at source directory. (subject as files were missed at source directory and in content i need to display the file names exist at source file directory. So that missed file will be generated by the customer based on this mail).
    Could you please let me know how to get the count of files from source file directory. if it is possible only with UDF please provide the Java code
    Best Regards,
    SARAN

    Do these files have some fixed names?
    Can you try to use the option Advanced Selection For Source File to make XI  pick all 5 files in one shot?
    Check this blog on the same -
    /people/mickael.huchet/blog/2006/09/18/xipi-how-to-exclude-files-in-a-sender-file-adapter
    If this is not a option - BPM sounds the only possible way.
    Regards,
    Bhavesh

Maybe you are looking for

  • Set and Get parameters using SAP memory.

    I have an ALV grid list that I want to transfer to a detail report when the user doubleclicks.  I have set up a parameter transaction associated with the detail report.  My problem is the transfer does not take place.  After the "CALL TRANSACTION" th

  • Premiere Pro CS3 Crashed, and now will no longer start back up again..

    I was working on a project today using Cs3, I've had it since spring and it always worked fine until tonight when i was editing a project.. In the middle of my editing the program unexpectedly froze than crashed... I then tried to restart it and i go

  • Loading a text file to a buffer

    Hi, I have a very simple question, I have a text file which I want to read and load it in a string buffer, but I don't want to user BufferedReader and append line by line, is it possible to load the text file into StringBuffer without any loops / app

  • Itunes on W8 will not play any files after upgrade to 11.0.4.4

    After following the prompt and updating Itunes on Windows 8 to version 11.0.4.4 on 6 June, Itunes no longer plays any audio or video files from my library. Pick a file and Itunes shows that it is playing (Pause button only) however nothing happens. T

  • Show keyword hierarchies in keywording panel

    In the list of keywords in the Keywording panel, show the relationship of keywords, and show ALL the keywords for the image.... For example, if I have keywords location arizona grand canyon and I asisgn "grand canyon" to an image, when I look at the