Sql to count the no. of entries

Hi all,
I know that we can count the no. of entries with
SY-DBCNT,
but besides this, can I directly use sql statement, e.g. select count...
to count the no. of entries?
Thanks.

Hi Macy,
    We can use like this.
    SELECT count(*) into l_var1
           from <db table>
           where <cond>.
    I think the above statement solves your problem.
Regards,
Ganesh N

Similar Messages

  • Give me a way to count the number of entries in a  Database Table

    Hello All,
    I am writing a code to determine the number of  entries in a SAP/Custom table.
    Can you please suggest a proper approach and a good query.
    Thanks in advance.

    Hi,
    If you want to do it in a more generic way you can do the following:
    DATA: tblname(50),
          tp_rows TYPE i.
    tblname = 'MARA'.
    SELECT COUNT(*)
    FROM (tblname)
    INTO tp_rows.
    IF sy-subrc <> 0.
      CLEAR tp_rows.
    ENDIF.
    At runtime the table is being determined and in this case it's set to MARA. The value of the number of rows is in the variable tp_rows.
    Best regards,
    Guido Koopmann

  • Program (PL/SQL) for count the registers of all tables in a schema

    Hi...
    I create a little program , for count the registers of all tables in the schema...
    If you need , send me your email...
    Atte
    Hector

    Hi,
    You can create a script by yourself by executing the script mentioned below:
    Connect as sys or system....
    SQL> spool test.sql
    SQL> select 'select count(*) from '||owner||'.'||table_name||';' from dba_tables;
    SQL> spool off;
    Hope this helps.
    Regards,
    -Praveen.
    http://myracle.wordpress.com

  • SQL to count the number of days between two dates

    Does any one have or know how to count the number of days/weeks between 2 dates.
    I have thought about using MONTHS_BETWEEN, but do not know how to make it accurate down to one day?
    Any suggestions would be appreciated.

    here are the different queries I came up with to do this, you may want to check it for perticular cases involving Sun and Sat as start and end dates.
    select to_number(to_char(to_date('21-JUL-00','dd-mon-yy'), 'ww'))
    - to_number(to_char(to_date('10-JUL-00','dd-mon-yy'), 'ww')) from dual;
    select (Next_Day(to_date('21-JUL-00','dd-mon-yy')-1, 'Sunday')
    - Next_Day(to_date('10-JUL-00','dd-mon-yy')-1, 'Sunday'))/7 from dual;
    select (Next_Day(to_date('21-JUL-00','dd-mon-yy')-6, 'Sunday')
    - Next_Day(to_date('10-JUL-00','dd-mon-yy')-6, 'Sunday'))/7 from dual;
    null

  • How do I count the unique text entries in a column

    I want to count thenumber of unique text entries in a column how do I do that?

    Or, if you will need to do this on different documents, you can copy this script into AppleScript Editor, select the cells in whichever document you are working on, and run. No need to set up the formulas and extra column again.
    SG
    --select range of cells, run; provides count of distinct values
    tell application "Numbers" to tell the front document to tell active sheet
              set selectedTable to (the first table whose class of selection range is range)
              tell selectedTable to tell the selection range
                        set distinctValues to {}
                        repeat with aCell in its cells
                                  tell aCell
                                            if its value is not in distinctValues then ¬
                                                      copy its value to the end of distinctValues
                                  end tell
                        end repeat
                        return count of distinctValues
              end tell
    end tell
    --end of script

  • How to count the per group-entries and put them in the new table

    Hello Guru,
    I want to sort the table cdhdr.
    for example :
      SELECT objectclas objectid changenr   *******
      INTO TABLE cdhdr_data
      FROM cdhdr
      WHERE ( ********) AND
            objectclas = i_objectclas
    The problem that I need to order the table by objectclas and objectid.
    Let say objectclas is always MATERIAL.
    Let's assume our key is changenr. May be our key will change to "objectclas objectid".
    So, my problem that I need to get the number of the same "objectid" with different "changenr".
    And also I need to put the count number of each object id with different changenr in the table cdhdr_data.
    For example
    objectclas        objectid       changenr      count
    MATERIAL      00***001      1                   3
    MATERIAL      00***001      4                   3
    MATERIAL      00***001      7                   3
    MATERIAL      00***005      2                   2
    MATERIAL      00***005      6                   2
    MATERIAL      00***003      5                   2
    MATERIAL      00***003      3                   2
    So later I'm going to use it.
    LOOP AT cdhdr_data FROM sy-tabix TO ( sy-tabix + cdhdr_dat ( sy-tabix ) + count - 1 )
    some optimized cdpos processing
    IF entry found.
    *don't loose time
    *change the boundery
    sy-tabix = count
    ENDIF.
    ENDLOOP.
    Best Regards,
    Kais

    Hi Marcin,
    Thanks for replying.
    I'm having a trouble.
    Let say I got an error on insert into ****.
    It says me that the object (i_)cdhdr_data is not known.
    Why, should I avoid to put objectclas = i_objectclas there.
    I need to have MATERIAL OR DOKUMENT.
    I can't just put 10000entries like that.
    I'm also sceptic about how much this operation will cost.
    Because I need to proceed the data with cdpos.
    And This's why I'm doing that.
    Later with this implementation I'm gone use LOOP AT *** FROM sy-tabix TO ****.
    If I use my method, it will cost lower than inserting, changing, ...
    I rather ignore the objectid and don't make any processing.
    But with your solution I can say its rapidly.
    Let assume there's n entries in cdhdr and m entries per n in cdpos.
    So my algorithm will select n entries and will follow n*m entries but some of them will be proceeded an other not.
    in cdhdr :
    for n entries : n * 1 selecting
    in cdpos :
    always : n*m comparing,
    processing between : n1 - nm
    With you algorithm we will do :
    in cdhdr :
    for n entries : n* (1 selection + 1 modifing + 1 appending) <=> each operation cost O(1)
    in cdpos :
    for comparing between : n1 - nm
    processing between : n1 - nm
    Let see the middle value :
    your case :
    in cdhdr  we have : n * O(3) ~ n * O(1) ~ O(n)
    in cdpos :
    O(c(nm)/2) + O(p(nm))2) ~ O((cp)((nm)/2)) ~ O(d(nm))  d= (cp)/2 ~ p/2
    we know that O(c*n) ~ O (n) ; c ist a constant
    c : comparing cost
    p : processing cost
    p >> c
    my case :
    in cdhdr  we have : n * O(1) ~ O(n)
    in cdpos :
    O(c(nm)) + O(p((nm)/2)) ~ ? maybe O(d(nm)) d = c + (p/2) ~ p/2
    c : comparing cost
    p : processing cost
    p >> c
    Ok, this in theorie, but in reality I've no idea.
    Is there a mathematician there ?
    Regards,
    Kais
    FORM get_cdhdr_data_modified_1
      USING
        i_from_date TYPE dats
        i_from_time TYPE terf
        i_to_date TYPE dats
        i_to_time TYPE terf
        i_objectclas TYPE j_objnr
      CHANGING
        cdhdr_data TYPE SORTED TABLE.
    types: begin of t_cdhdr_data,
                objectclas type cdhdr-objectclas,
                objectid type cdhdr-objectid,
                changenr type cdhdr-changenr,
                count type i,
          end of t_cdhdr_data.
      DATA : i_cdhdr_data type table of t_cdhdr_data with key objectclas objectid changenr with header line.
      DATA: st_index LIKE sy-tabix, count TYPE i.
      SELECT objectclas objectid changenr
      INTO TABLE i_cdhdr_data
      FROM cdhdr
      WHERE ( ( udate GT i_from_date AND udate LT i_to_date ) OR
              ( udate EQ i_from_date AND udate NE i_to_date AND utime GE i_from_time ) OR
              ( udate EQ i_to_date AND ( udate NE i_from_date OR utime GE i_from_time ) AND utime LE i_to_time )
            ) AND
            objectclas = i_objectclas.
      INSERT INTO i_cdhdr_data FROM i_cdhdr_data.
    ENDSELECT.
    LOOP AT i_cdhdr_data.
      AT NEW objectid.
        "remember start position
        st_index = sy-tabix.
      endat
      at end of objectid.
      count = sy-tabix - st_index + 1. "count accual position
      cdhrd_data-count = count. "now you have how many entries are in each objectid
      MODIFY TABLE i_cdhdr_data FROM i_cdhdr_data.
    ENDAT.
    ENDLOOP.

  • Count the number of entries per calendar

    Wondering if there is any way to know how many entries I have in a specific calendar.
    Would like to be able to delete the empty ones.
    Thanks!

    Try this in Script Editor:
    AK
    click here to open this script in your editor<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">tell application "iCal"
    repeat with ThisCal in calendars
    set EventCount to count of events of ThisCal
    set ToDoCount to count of todos of ThisCal
    display dialog (name of ThisCal & " - Events:  " & EventCount & "  ToDos:  " & ToDoCount)
    end repeat
    end tell</pre>

  • To count the repeated entries in a XML document.

    HOW TO COUNT THE REPEATED  NUMBER OF ENTRIES IN A XML DOCUMENT USING THE SAP REPORT PROGRAM?
      <?xml version="1.0" encoding="utf-16" ?>
    - <ROOT>
    - <SYSTEMDETAILS>
    - <item>
      <SYSDETAILSNAME>CODE</SYSDETAILSNAME>
      <SYSDETAILS>00</SYSDETAILS>
      </item>
    - <item>
      <SYSDETAILSNAME>LICENSE</SYSDETAILSNAME>
      <SYSDETAILS>INITIAL</SYSDETAILS>
      </item>
    - <item>
      <SYSDETAILSNAME>BASIS RELEASE</SYSDETAILSNAME>
      <SYSDETAILS>700</SYSDETAILS>
      </item>
    - <item>
      <SYSDETAILSNAME>SYSTEM NAME</SYSDETAILSNAME>
      <SYSDETAILS>IS3</SYSDETAILS>
      </item>
    - <item>
      <SYSDETAILSNAME>CLIENT</SYSDETAILSNAME>
      <SYSDETAILS>800</SYSDETAILS>
      </item>
    - <item>
      <SYSDETAILSNAME>LOCLANG</SYSDETAILSNAME>
      <SYSDETAILS>English</SYSDETAILS>
      </item>
      </SYSTEMDETAILS>
    - <ACH>
    - <item>
      <NAME>HLA0009999</NAME>
      <TLEVEL>01</TLEVEL>
      <TEXT>SAP</TEXT>
      <TEXT4>Application Components</TEXT4>
      <TEXTLOC>Application Components</TEXTLOC>
      </item>
    <item>
      <NAME>ABA0000311</NAME>
      <TLEVEL>02</TLEVEL>
      <TEXT>AP</TEXT>
      <TEXT4>Application Platform</TEXT4>
      <TEXTLOC>Application Platform</TEXTLOC>
      </item>
    - <item>
      <NAME>KPE0000001</NAME>
      <TLEVEL>03</TLEVEL>
      <TEXT>AP-PPE</TEXT>
      <TEXT4>Integrated Product and Process Engineering</TEXT4>
      <TEXTLOC>Integrated Product and Process Engineering</TEXTLOC>
      </item>
    SAY THE  BOLD PART SHOWS 1 USER ,SO HOW MANY TIMES THE SAME USER APPEARS IN THE DOCUMENT.
    HOW CAN I FIND THAT?

    If the same content of file already thr in the Internal table as 1 STRING/LINE then you can loop the internal table count the entries which one you want like
    Kanagaraja L

  • Count the number of times a character is in a string using pl/sql

    I need to count the number of times ":" appers in the string ":XXX:CCC:BBB:".
    I have sound some solution using SQL but I do not want the context switch.
    Also I am on 10g so I can not use REGEXP_COUNT.
    Any help would be great.

    Hi,
    length(REGEXP_REPLACE(':XXX:CCC:BBB:','[[:alnum:]]'))counts all kinds of punctuation, spaces, etc., not just colons. Change any (or all) of the colons to periods and it will still return 4. Use '[^:]' instead of '[[:alnum:]]' if you really want to count just colons.
    Also, "SELECT ... FROM dual" is usually needed only in SQL*Plus or similar front end tools. In PL/SQL, you can call functions without a query, like this:
    x := NVL (LENGTH (REGEXP_REPLACE (txt, '[^:]')), 0);

  • Counting the duplicate entries without looping itab.

    Hi ,
    I want to count the duplicate entries in  itab without looping
    the itab.
    can any one help me....

    If you just want to know the number of duplicate entries:
    DATA:
      zlt_itab1 TYPE ....
      zlt_itab2 LIKE itab1,
      zlv_lines TYPE i,
    *-Copy table
    zlt_itab2 = zlt_itab1
    *-Sort on field to count duplicates:
    SORT zlt_itab2 BY <field for counting duplicates>
    *-Total number of lines:
    zlv_lines = LINES( zlt_itab2).
    *-Remove duplicates:
    DELETE ADJACENT DUPLICATES FROM zlt_itab2.
    *-Calculate number of duplicates:
    zlv_lines = zlv_lines - LINES(zlt_itab1).
    Regards,
    John.

  • What is the problem with native dynamic sql when counting rows in all table

    what is the problem with native dynamic sql when counting rows in all table?Giving an error "table or view does not exist". Thanks.
    DECLARE
    v_sql_string varchar2(1000);
    v_no_of_rows number;
    BEGIN
    for i in ( select table_name from all_tables )
    loop
    v_sql_string := ' select count(1) from ' || i.table_name;
    dbms_output.put_line( v_sql_string );
    --execute immediate v_sql_string into v_no_of_rows;
    end loop;
    END;

    Usually your problem can be described with 'Who cares'. I mean, for what reason do you do this? I doubt that there's a business need to get 100 % accurate answers for this. Normally such things are used to get a picture about the growth of data.
    Personally I would prefer to have up-to-date statistics for all tables and just query the number of rows from there. Sufficient for me in < 99 % of all cases.
    Just my $ .02...

  • Ho to count the total number of rows Sql Reporting Services Report Builder's Dataset after filteration based on parameter

    Hi to all,
                 I have parameter and data-set i.e consists of SharePoint List items,Data-set get's  filters and I need to count the total rows of the data-set i.e I get after filtration.
    Thanks, Quality Communication Provides Quality Work. Mohammad Siddiqali.

    Hi siddiqali,
    Thanks for the question and Destin Joy’s reply. Please try to add the filter in the dataset level rather than the data region
    level. Detail steps as below.
    1.      
    Double-click the dataset name in the Report Data window, click Filters in the left panel.
    2.      
    Click Add button, choose Admission Date in the Expression drop-down list. Type in the Value textbox with the parameter name: @selectDate.
    3.      
    Right-click the cell that your identified by the red circle, select Expression, type in it with:
    =CountRows("DataSetName")
    Thanks,
    Sharp Wang
    Please remember to mark the replies as answers if they help you and unmark them if they provide no help.

  • Given various date ranges, count the occurrences of dates in PL/SQL

    i have a table of employees that have a start date and end date on a project. Some employees end date is null because they are still working on the project. So I want to find for each day in JAN, how many people on working on the project.
    So I generate the dates JAN 1 - 31 with this:
    Declare
      days DATE := To_Date('01-JAN-11','dd-mon-yy');
    BEGIN
      FOR days IN 1..31
      LOOP
        Dbms_Output.Put_Line(TO_CHAR(days ,'dd-Mon-yy'));
        days  := days  + 1;
      END LOOP;
    END; For employee X (ID 123), his start date is 1st and end date is 4th. So I use this query to list the dates he worked on (Jan1 jan2 jan3 jan4):
    DECLARE
    da Number;
    days Date;     
    sta emp.start%Type;
    BEGIN
    Select end-start+1
    Into da
    From emp
    where emp_id = 123;
    Select start
    Into sta
    From emp
    Where emp_id = 123;
      days  := To_Date(sta,'dd-mon-yy');
    FOR i IN 1..da
      LOOP
        Dbms_Output.Put_Line(TO_CHAR(days ,'dd-Mon-yy'));
        days  := days  + 1;
      END LOOP;
    END;Now the problem I am having is trying to do a for loop to check the work days from each employee in the table. I guess I need to iterate over the employee IDs. The above code, I entered the empoyee ID myself to find his work days, but I am trying to loop over all the employees to find and count the days. Any help on this part?
    Ultimately I am trying to get this:
    Day Count
    Jan 1 5
    Jan 2 3
    Jan 3 1
    Jan 31 5

    select  project_id,
            dt,
            nvl(count(emp_id),0)
      from  employee_projects,
            (select date '2010-12-31' + level dt from dual connect by date '2010-12-31' + level <= date '2011-01-31')
      where dt between start_date(+) and nvl(end_date(+),sysdate)
      group by project_id,
               dt
    /SY.
    Edited by: Solomon Yakobson on Jan 18, 2011 5:01 PM

  • How to count the occurance of the data entry on OBIEE answers

    Hello guys
    I have one report that contains a column call type. In the report that I am creating, there are 200 rows in that column, but there are really just 4 types of call type; "A,B,C,D"
    So in my report it looks like this
    Call type other dim and fact
    A
    A
    A
    B
    B
    C
    D
    D
    D
    D
    Now I need to add one more column said call counts, which needs to count the occurance of each call types:
    Call type count others
    A 3
    B 2
    C 1
    D 4
    So how would I be able to achieve this on answers? I used "count" function on "count" column, but it is counting all the rows without distinguishing the call type
    Please let me know
    Thanks

    Hi,
    Looks to me like this should be a measure within the RPD rather than something you try to do at the presentation level. Any simple "# of <x>" measure will work like you describe, it should just do a simple count on something unique in the table and have an aggregation rule set, OBIEE will then automatically group by this in your report by distinct call type without you having to do anything complex.
    Regards,
    Matt

  • How do I count the number of unread emails in WebCenter ?

    how can I show unread emails counter on webcenter spaces ( I used the default WC Mail task flow )

    Hi Euler,
    interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
    There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
    Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
    In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed.

Maybe you are looking for