How to write optimized select statements for this requirement

I.     G/L Account No. Info: Get all the list of G/L Account no. , company code and the corresponding long description from SKB1 & SKAT tables based on the G/L Account no. and company code values entered in the selection screen.
II.     No. of transactions posted: For each of the Company code & Posting date or fiscal year/ period combination, select all document numbers from BKPF table into an internal table. For each of the company code, GL Account no combination find out no. of distinct records in the BSEG table (or combination of BSIK, BSAK, BSID, BSAD, BSIS & BSAS tables) to get the No. of transactions posted.
III.     For Last posting FY/period: for each G/L account, Company code combination, determine the MAX (Doc. No) in BSEG, and look up the corresponding document in BKPF table to get the last posting FY/Period.
Thanks,
Prakash.

I) with a query (sq01/2) and logical database SDF
or standard abap RFSKVZ00
II)a) select bkpf
   b) select count( * ) from bsik...
III) a)select max( belnr ) from bseg...
     b) selec single monat from bkpf
A.

Similar Messages

  • Regarding select statement for this requirement

    Hi................
    good evening
    here is a requirement.
    i want to retrieve data from the following table.but how to join these table is my dought.
    tables  fields
    t001w--werks " plant id
    t001w--name1 " pl;ant name
    t001w--regio " plant address
    ekko--ebeln " purchase  order
    ekko-erdat : creation date
    ekko-ernam "name of the person
    ekpo-ebelp " item
    ekpo-bstyp "purchase order type
    eket-erdat " delivery date
    mara-matnr " material number
    these are the tables and fields.now we want to retrive data from these tables
    how we have to code select statement.
    selection-screen is
    plant id
    order type
    delivery date
    please provide select statement for this requirement.
    thanks and regards.
    k.swaminath  reddy.

    Is this what you are looking for?
    SQL> CREATE OR REPLACE FUNCTION f_team
      2  RETURN VARCHAR2
      3  IS
      4    s_return VARCHAR2(500);
      5  BEGIN
      6    FOR i IN ( select team from t_team order by 1) LOOP
      7      s_return := s_return || i.team || ', ';
      8    END LOOP;
      9   
    10    RETURN substr(s_return, 1, length(s_return) - 2);
    11  END;
    12  /
    Function created.
    SQL>  SELECT f_team FROM dual;
    F_TEAM
    Australia, Bangladesh, England, India, Kenya, Pakistan, South Africa, UAE, USA, West Indies, Zimbabwe
    SQL>

  • How to write Select statement for this codition

    I need to check whether SGTXT contains BELNR value.
    SGTXT is a text field and It should be matched with BELNR
    How to write select statement for this.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT should have the given BELNR Value.
    Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.

    Hi,
    data temp(12).
    concatenate '%' belnr '%' into temp.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT like temp.
    If belnr is having multiple values,just create a internal table as follows.
    types : begin of ty,
            belnr....
            temp(12),
            end of ty.
    data itab_ type standard table of ty.
    data wa type ty.
    loop at itab into wa.
    concatenate '%' wa-belnr '%' into wa-temp.
    modify itab from wa index sy-tabix transporting temp.
    endloop.
    Change your select statement accordingly.
    Kindly reward poits if it helps.

  • How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column

    Please Help!!!
    How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column.
                                      January 2014         January
    2013                            +/-
                    Region   Entry   Exit  Total    Entry   Exit   Total   (Total of Jan2014-Total of Jan2013)
                    A               2         3      
    40        5       7        30                    40-30= 10

    What is a table structure? Sorry cannot test it right now..
    SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
    FROM tbl
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Write an sql select statement for this problem?????????????????

    Hi frenz, i m bharath a new bee to oracle,my problem is
    the given table is
    userid billno amount
    1 101 1000
    2 102 2000
    3 103 3000
    4 104 4000
    output table should be:
    userid billno amount total*
    1 101 1000
    2 102 2000 *3000*
    3 103 3000 *6000*
    4 104 4000 *10000*
    I need a select query for the above output.
    i.e,here i calculated total as sum(amount) for each row,i.e,3000 = 1000+2000,6000 = 1000+2000+3000,10000 = 1000+2000+3000+4000 by this way my calculation for total field
    kindly send me a query.

    This is trivial with analytics:
    SQL> select empno, sal, sum(sal) over (order by empno)
      2  from emp
      3  /
         EMPNO        SAL SUM(SAL)OVER(ORDERBYEMPNO)
          7369        800                        800
          7499       1600                       2400
          7521       1250                       3650
          7566       2975                       6625
          7654       1250                       7875
          7698       2850                      10725
          7782       2450                      13175
          7788       3000                      16175
          7839       5000                      21175
          7844       1500                      22675
          7876       1100                      23775
          7900        950                      24725
          7902       3000                      27725
          7934       1300                      29025
    14 rows selected.
    SQL> You might want to get your keyboard checked - the question mark key seems to be stuck.
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • Select statement for this???

    Hi
    I have table t where there are two columns
    it has the data in the following format..some of it is given below
    team_ID               Team
    1                 Australia
    2                 England
    3                 West Indies
    4                 India
    5                 Pakistan
    6                 South Africa
    7                 Zimbabwe
    8                 UAE
    9                 Bangladesh
    10                Kenya
    11                USA
    12
    13...
    14..
    so on
    [pre]
    I want a select statement that will show me the above data in the follwoing format:
    Australia, Bangladesh, England, India, Kenya, Pakistan, South Africa, UAE, USA, West Indies, Zimbabwe
    (note that the team names should always come in the Alphabetical format in the desired output..
    please tell me the query for this..
    regards,
    Asim.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Is this what you are looking for?
    SQL> CREATE OR REPLACE FUNCTION f_team
      2  RETURN VARCHAR2
      3  IS
      4    s_return VARCHAR2(500);
      5  BEGIN
      6    FOR i IN ( select team from t_team order by 1) LOOP
      7      s_return := s_return || i.team || ', ';
      8    END LOOP;
      9   
    10    RETURN substr(s_return, 1, length(s_return) - 2);
    11  END;
    12  /
    Function created.
    SQL>  SELECT f_team FROM dual;
    F_TEAM
    Australia, Bangladesh, England, India, Kenya, Pakistan, South Africa, UAE, USA, West Indies, Zimbabwe
    SQL>

  • How to write a sql query for this condition?

    i have one table with columns v_sub,v_visit and v_date and the structure is like this
    v_sub v_visit v_date
    1 visit-1 01-mar-09
    1 visit-2 05-mar-09
    1 visit-3 17-mar-09
    2 visit-1 04-feb-09
    2 visit-2 12-mar-09
    2 visit-3 20-mar-09
    i want to write a query which check weather it is in chronological order or not.(for v_sub,v_visit and v_date should be in chronological order as above)
    and i want to check the condition as below:
    v_sub v_visit v_date
    1 visit-1 01-mar-09
    1 visit-2 05-feb-09
    1 visit-3 17-mar-09
    2 visit-1 04-feb-09
    2 visit-2 12-jan-09
    2 visit-3 20-mar-09
    Thanks in advance

    use LAG function to get the previous date
    SQL> -- sample data
    SQL> with t
      2  as
      3  (
      4     select 1 v_sub, 'visit-1' v_visit, to_date('01-mar-09','dd-mon-yy') v_date from dual union all
      5     select 1, 'visit-2', to_date('05-mar-09','dd-mon-yy') from dual union all
      6     select 1, 'visit-3', to_date('17-mar-09','dd-mon-yy') from dual union all
      7     select 2, 'visit-1', to_date('04-feb-09','dd-mon-yy') from dual union all
      8     select 2, 'visit-2', to_date('12-mar-09','dd-mon-yy') from dual union all
      9     select 2, 'visit-3', to_date('20-mar-09','dd-mon-yy') from dual
    10  )
    11  -- end of sample data
    12  select v_sub, v_visit, v_date, lag(v_date) over(partition by v_sub order by v_visit, v_date) v_previous_date
    13    from t
    14  /
         V_SUB V_VISIT V_DATE    V_PREVIOU
             1 visit-1 01-MAR-09
             1 visit-2 05-MAR-09 01-MAR-09
             1 visit-3 17-MAR-09 05-MAR-09
             2 visit-1 04-FEB-09
             2 visit-2 12-MAR-09 04-FEB-09
             2 visit-3 20-MAR-09 12-MAR-09
    6 rows selected.Now you can check if the previous_date is less than v_date

  • How to write lead selection method for a  tree by nesting table column

    Hi,
    I have implemented a table with TreeByNestingTableColumn(To show the tree structure in the table).I am not able to get the selected row element in lead selection method.(I am able to get parent element.) .
    could anyone please tell me about this code?
    BR,
    Ashish

    Hi,
    Follow the below steps to the solution for your problem
    1. Create Action "LeadSelection" in View with parameter (name : 'seletedItem'
    and type : I<your node>Element
    2. Bind this action to Table property "onLeadSelec"
    3. In wdModify()
         IWDTable table = (IWDTable) view.getElement("Your table id");
         table.mappingOfOnLeadSelect().addSourceMapping("nodeElement", "selectedEle");
    4. In onActionLeadSelection()
         wdComponentAPI.getMessageManager().reportSuccess("Selected Item : "+selectedEle.get<Your Node Attribute>());
    Let me know if you need more clarification
    Thanks

  • How to create a generic SP for this requirment

    Hi all,
    i have a requirment like .....i have 10 sp's (sp1,sp2,sp3.....sp10) in a package named as 'generic_pkg'.
    procedure sp1 (abc IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2);
    procedure sp2 (xyz IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2,
    sp_out2 OUT varchar2);
    procedure sp3 (pqr IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2,
    sp_out2 OUT varchar2,
    sp_out3 OUT varchar2);
    procedure sp10 (pqr IN varchar2,
    parameter IN varchar2,
    sp_out1 OUT varchar2,
    sp_out2 OUT varchar2,
    sp_out3 OUT varchar2,
    sp_out4 OUT varchar2,
    sp_out5 OUT varchar2,
    sp_out6 OUT varchar2,
    sp_out7 OUT varchar2,
    sp_out8 OUT varchar2,
    sp_out9 OUT varchar2,
    sp_out10 OUT varchar2);
    now i want to create a new SP. the new sp is having input parameters as
    procedure new_sp (sp_name IN varchar2,
    parameter IN varchar2,
    sp_output OUT varchar2);
    now i will get sp name as input parameter and i have to check whether that sp is there on generic_pkg package or not.
    if sp found , then i have to call that sp and have to return output.
    the new_sp should be generic(i.e the new_sp should compatable to call any sp in the package 'generic_pkg'). my doubt is all the 10 sp's are having same inputs, but different no of outputs. How can i make new_sp as a generic sp?
    procedure new_sp (sp_name IN varchar2,
    parameter IN varchar2,
    sp_output OUT varchar2); ---- ? how to handle?
    please anybody can guid me with example....
    thanks in advance.....
    Edited by: user9041629 on Sep 7, 2010 6:01 AM

    Your 'requirement' of being able to submit a procedure name as parameter will result in using dynamic SQL all over the place.
    Consequently you violate the very reason why PL/SQL was invented: to diminish parsing
    I pray you don't have any customers who are going to buy this 'product'. They are not to be envied.
    I pray also you have a good lawyer.
    Sybrand Bakker
    Senior Oracle DBA

  • How to use time series functions for this requirement

    we are on OBIEE 11g (11.1.1.5)
    Any pointers and links are really helpful.
    I have a requirement where YTD sales are displayed in a column. We wan to compare that number to what that number was last year at the same time. Tried to use TODATE, AGO and it did not work.
    || used for column seperation below.
    ProductGroup || YTD Sales Rev||YTD Sales Rev 1 Year Ago||YTD Sales Rev 2 Years Ago
    Climate Solutions || 1.7 mil (1/1/2011 - 7/1/2011) || 1.45 mil (1/1/2010 - 7/1/2010) || 1.15 mil (1/1/2009 - 7/1/2009)
    Thanks in advance
    kris
    Edited by: user566193 on Aug 10, 2011 6:06 PM

    Kris,
    Basically you want to combine the 2 time series functions here i.e. TODATE & AGO.
    Here you go..
    You can create first a YTD logical column in BMM say YTD Sales Rev..Then create another logical column with calculation as AGO(YTD Sales Rev, YEARDIM, 1) or AGO(YTD Sales Rev, MONTHDIM, 12).
    Similarly, you create other measures...OBIEE 11g has time series function in Answers as well but I'd say try to create using RPD as you to calculate 1 logical column based on another. Better to push it on RPD side.
    Hope this helps

  • Select statement for summing values in column?

    How to write a select statement for sap standard table which contains data  as given below
    col1        col2
    A     10
    A     20
    A     30
    B     50
    B     60
    C     70
    Need the output of select in  internal table as given below
    A     60
    B     110
    C     70
    Regards,
    Rachel

    Thanks for all the valuable input.
    Below I have used sum in select statement(check case 2"),but i am not getting required o/p.
    Kindly guide me.
    case1 :
    select aebeln aebelp bpackno  bmenge
    into corresponding fields of table itab
    from ( eslh as a inner join esll as b
    on bpackno = apackno )
    where a~ebeln = 6000000100
    and a~ebelp = 00010
    and a~packno = '0000001025'
    order  by aebeln aebelp b~packno .
    O/p for the above .
    ebeln                       ebelp         packno                             menge
    6000000100     00010     0000001025              6.000
    6000000100     00010     0000001025               5.000
    6000000100     00010     0000001025              2.000
    6000000100     00010     0000001025              1.000
    6000000100     00010     0000001025              2.000
    case2:
    select aebeln aebelp bpackno  sum( bmenge )
    into corresponding fields of table itab
    from ( eslh as a inner join esll as b
    on bpackno = apackno )
    where a~ebeln = 6000000100
    and a~ebelp = 00010
    and a~packno = '0000001025'
    group by aebeln aebelp b~packno
    order  by aebeln aebelp b~packno .
    6000000100     00010     0000001025     0.000
    Edited by: Rachel on Nov 25, 2008 11:45 AM
    Edited by: Rachel on Nov 25, 2008 11:46 AM

  • How  to write select query for this

    Hi,
    I had a html form and in the for i had drop down box and it needs to select multiple values from the drop down box. When i select multiple values then i have to write the SQL select statement  query .
    When i try to write the select statement and trying to run i am getting error.
    select * from Table
    where emo_no = '1,2,3'
    this is how i write query please suggest me how  to write query for selecting multiple values from the drop down box.
    Thanks

    select * from Table
    where emo_no in ( 1,2,3)
    for integer values
    select * from Table
    where emo_no in ('1','2','3')
    for characters
    If we talk about large scale applications that may have millions of records, I would suggest this.
    declare @t table (v int)
    insert into t (v) values (1)
    insert into t (v) valves (2)
    insert into t (v) values (3)
    select *
    from table
         inner join @t t on table.emo_no = t.v
    Using "in" for a where clause is not so bad for filtering on a few values, but if you are filtering a lot of rows and a lot of values (emo_no) the performance degrades quickly for some reasons beyond the scope of this.
    This is just one solution, I'll through this out as well, instead of an in memory (@t) table, doing a disk based temp table (#t) and creating an index on the column "v".
    create table #t (v int)
    insert into #t (v) values (1)
    insert into #t (v) valves (2)
    insert into #t (v) values (3)
    create index ix_t on #t (v)
    select *
    from table
         inner join #t t on table.emo_no = t.v
    drop table #t
    Pardon any syntax errors and careful using a drop statement.
    Sometimes in memory tables work better than disk temp tables, it takes some testing and trial and error depending on your datasets to determine the best solution.
    Probably too much info  ;-)
    Byron Mann
    [email protected]
    [email protected]
    Software Architect
    hosting.com | hostmysite.com
    http://www.hostmysite.com/?utm_source=bb

  • How to display number of rows as columns in a select statement? This is on

    How to display number of rows as columns in a select statement? This is on 10g R2.
    Thanks,
    R

    For the current (ie. row 1 of 100)
    row_number over (order by -pick_a_column_set) as rnfor the total number of columns returned in your query
    count(*) over() as total_count

  • How to execute a SELECT statement  in java??

    Hello !!
    In my java program , i need to delete a record of number X, so
    i accept the number X from the keyboard
    Then before deleting it
    i want the program to show me the name, age of the record which has the number X
    How to do this

    hello kylas
    actually i didnt get why this program example?? wats
    its executing ??? Look at reply #3 in your other thread:
    http://forum.java.sun.com/thread.jspa?threadID=713289&messageID=4126346
    Notice the similarity? You've now asked "How to delete a record in Java" and "how to execute a select statement in java". You may have noticed that, aside from the SQL and the call to execute and executeUpdate (for delete) it's the same code. This is because you don't so much do these things in Java, you do them in SQL. The Java code simply asks the Driver to execute whatever SQL you write. So, I really hope your next post isn't "how do I execute an UPDATE statement in Java".
    Good Luck
    Lee

  • Need Select statement for fetch the details

    Hi
      i want to fetch particular customer wise sales orderds and that sales order No  and  date of sales order was created..  and  that sales order related PO No  and Materials ..
    for this..   how can i write an executable programm.. is it needed to  define seperate  internal tables or single internal table is enough  ?
    what is the select statement for fetching  all these details..
    any help will be appriciated
    Thanks
    Bbau

    custmer master table is KNA1  knb1  knbk
    sales data tables r  VBAK VBAP VBEP
    Material data  MARA, MARAC, MARD
    PO RELATED ekko  ekpo  eket
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Feb 13, 2008 3:04 PM

Maybe you are looking for

  • How to load data from one Infobject into another in the same system??

    Hello All,    i need to load hierarchy data (already existing in 1 Infobject) into another newly created Infobject in the same BW system.Is there a way to do it without involving flat files?? Thanks soo much in advance Regards, Priya

  • Mac running slow and crashing

    Lately, my mac has been running slow, freezing, restarting, and this is new... I have a lot of things in imovie... so I presume it might be that, but this is ridiculous!  It is constantlly beachballin'!  How do I make my Mac perform like it did when

  • Disk Utility:  Backup to partition on external drive?

    Hi people. Would be glad of an answer and any comments on this. I have 3 Macs at home, a new G5 dual core and 2 G4 imacs, networked wirelessly. At this point I only backup my G5 to a second internal HD, by using Disk Utility's 'Restore' function. My

  • Lumia 520 cant connect to Wifi

    For heavens sake .Lumia 520 is a smartphone that cant connect to wifi. very useless. I have tried all those steps abt settings on the router without success. i love my fone but i feel disappointed with it..Feel like i can return it to shop

  • KVM for mixed DVI D-sub setup

    I can't find one of the KVM discussions I recall, but I don't think it addressed this. I would love to share a keyboard, mouse, and one or more monitors with my 3 PCs.  But the laptop and one PC are old (meaning D-sub video outputs), and the other is