Add cols to query

I have this query:
select state_name,sum(cnt_active) TotalActiveVouchers, sum(sum_active) TotalActiveValue,
sum(cnt_inactive) TotalOtherVouchers, sum(sum_inactive) TotalOtherValue,
sum(cnt_expired) TotalRedeemedVouchers, sum(sum_expired) TotalRedeemedValue
from(select state_name,decode(mp.status,'12',1,0) cnt_active,
decode( mp.status,'12',mh.chargesheet_name,0) sum_active,decode(mp.status,'18',1,0) cnt_inactive,
decode( mp.status,'18',mh.chargesheet_name,0) sum_inactive,
decode(mp.status,'',1,'5',1,'16',1,'17',1,0) cnt_expired,
decode( mp.status,'',mh.chargesheet_name,'5',mh.chargesheet_name,'16',mh.chargesheet_name,'17',mh.chargesheet_name,0) sum_expired
from mst_pindetails mp, mst_batchno mb,mst_chargesheet_hdr mh,
mst_state ms where mp.swhbatchcode=mb.swhbatchcode and mb.chargesheetno = mh.chargesheet_code and trim(ms.state_id) = mb.statecode)
group by state_name order by state_name
This query displays results of statename,active count, active value,redeem count, redeemvalue, other count, othervalue
I want two more columns to be displayed status and attribute_date which come from mst_pindetails table ... i dont want to use them in groupby
I need these because if i add these two cols also to this query i can use it in an application where i can perform the search criteria based on these two... if they are in the query then only i will be able to use it in application

it gives me 60740 rows .... actually i should get only 6 rows based on statename... only 6 states are there,.... but different status and attribute_date are there thats why iam getting more rows ... can i get only 6 states and can i make status and attribute date as null when results are displayed
how to set a column value to null or zero in the results displayed..just use your original query and add null as status and null as attribute_date
that will give you the columns with no value.
/* Formatted on 7/6/2011 10:25:39 AM (QP5 v5.149.1003.31008) */
  SELECT state_name,
         NULL status,
         NULL attribute_date,
         SUM (cnt_active) TotalActiveVouchers,
         SUM (sum_active) TotalActiveValue,
         SUM (cnt_inactive) TotalOtherVouchers,
         SUM (sum_inactive) TotalOtherValue,
         SUM (cnt_expired) TotalRedeemedVouchers,
         SUM (sum_expired) TotalRedeemedValue
    FROM (SELECT state_name,
                 DECODE (mp.status, '12', 1, 0) cnt_active,
                 DECODE (mp.status, '12', mh.chargesheet_name, 0) sum_active,
                 DECODE (mp.status, '18', 1, 0) cnt_inactive,
                 DECODE (mp.status, '18', mh.chargesheet_name, 0) sum_inactive,
                 DECODE (mp.status,  '', 1,  '5', 1,  '16', 1,  '17', 1,  0)
                    cnt_expired,
                 DECODE (mp.status,
                         '', mh.chargesheet_name,
                         '5', mh.chargesheet_name,
                         '16', mh.chargesheet_name,
                         '17', mh.chargesheet_name,
                         0)
                    sum_expired
            FROM mst_pindetails mp,
                 mst_batchno mb,
                 mst_chargesheet_hdr mh,
                 mst_state ms
           WHERE     mp.swhbatchcode = mb.swhbatchcode
                 AND mb.chargesheetno = mh.chargesheet_code
                 AND TRIM (ms.state_id) = mb.statecode)
GROUP BY state_name
ORDER BY state_name

Similar Messages

  • How to unlock the request for a report and add the same query to new reques

    hi,
         how to unlock the request for a  and add the same query to new reques

    You can unlock in SE03 tcode.
    Goto tcode SE01, give the transport number --> display --> double click on the transport --> in the next screen select all the elements --> delete --> save.
    To attach it to another transport, In RSA1, click on transport connection> Choose Object types> query elements --> here you can find your query/ or you can search, which you can drag to right and attach to the transport (using truck button).

  • Function Add a combined query

    Hello,
    I created two different universes based on a SAP BEx query. I can create reports with WebI based on both universes thats no problem.
    If I want to create a combined query based on that 2 universes it is not possible the button "Add a combined query" is not available. Does anybody know when this will be available? Or am I doing something wrong?
    Thanks for your reply.
    Kind regards,
    Jule
    System Information: BIP 4.0 SP 02 Patch 11

    Ok, could you please try the following:
    1. Import the universe which you want to use.
    2. Go to File>Parameters>SQL tab.
    3. Check the checkbox for "Allow use of union,intersect and minus operator".
    4. Save and export that universe.
    Then if the problem persists, could you please test if the issue occurs with the administrator account?
    Kind Regards,

  • Can we add button in query region  along with go and clear

    Hi Friends,
    i have a requirement as below steps-
    1)i have developed search pgae by using query regiion
    2) in pgae,first we have search items,go and clear(submit buttons), table region.
    3)here go and clear buttons came automatically.
    4) i can able to add button in front of the page and end of the page.
    4) my requirement is i need to add one more button along with go and clear(here go and clear button are in between search items and table region) .
    5)i am not able to add button along with go and clear.
    Can any one know how to do this--
    Thanks in Advance
    vamshi

    Hi Vamshi,
    You can not create extra buttons in Standard Query region.
    Alternatively you can create your custom region for the search and there you can add a button. If you don't need advanced region, you can create the custom region in place of standard one.
    Anoop

  • Field add in abap-query

    Hai all,
    Kindly advise me how to add the new fields in report which has already created via ABAP-Query programming.
    Regards,
    Renuga.A

    What kind of report? Usually, you have to add the field in the table declaration and then also in the SQL query. After that, include the field in what kind of report you are using.

  • Add "cost center" query to a start condition?

    Hi there,
    we got a new requirement for one of our plants.
    We're on SRM 5.0 classic scenario.
    Is it possible to add a "cost center" query to a specific start condition (SWB_PROCUREMENT) of a workflow?
    E.g. if a user uses cost center 4711 for a shopping cart item a specific cost center responsible xyz should approve this item.
    If the user uses another cost center 4712 for a second item in this shopping cart this item should be approved by another cost center responsible abc.
    Is that somehow possible ?
    So far I did not find a suitable expression for cost center.
    Thanks in advance for your answers.
    Best regards,
    Henning

    Hi Masa,
    thanks for your answer. Perhaps you also have a hint for the following:
    I can't really find in the metioned thread or in note 731637 what happens if a SC with several items is partially approved.
    Example:
    SC with 3 items:
    item 1 cc 1000
    item 2 cc 2000
    item 3 cc 1000
    Let's say item 1+3 have been approved by the approver found by badi and WS14500015. Is a PO or a purchase requisition created in backend? Or is it only created after the whole SC has been approved (i.e. also item 2).
    Thanks for a hint and best regards,
    Henning

  • Add calculated field (Query - SQ01)

    Hi to all,
    I would know how can i add a calculated field to a Query (SQ01) ?
    Can you give me an example of abap code to insert in CODING section ?
    thks

    Hi,
    My understanding about your question is you want to display the total for two standard fields in a table,
    1) Personalize the table and make true for the property Total.
    2) If you want to calculate both the column total,
    Add a MessageStyledText via personalziation to the page, and extend the controller
    and in the ProcessRequest
    Get the handle of the AM and then ur attributes VO Attributes and traverse through the VO rows and get the total of both the columns
    and set the value to the newly created MessageStyledText.
    Let me you want any sample code for the second step.
    Thanks.
    With Regards,
    Kali.
    OSSi.

  • Error of ADD ON and Query Saving

    Hi
    Even after uploading the licence i am not able to register ADD ON as well as i cant save query.
    When i register ADD ON i receive error : wrong digital signature for addon installer
    When i save query i receive error:define numbering series in administration module
    Though i have allot licence to SAP ADD ONs and superuser.PL is 0.
    Whats the solution?

    hi,
        you only need to remove the traces from the sari table if u r getting this error on server also.for client system go to the drive in which sap is installed...open prog file..sap b1...then u will find 2 addon local registration file and a folder called addon..remove ur addon from that folder and in the file search for the string where ur addon was installed and remove it......dont try it if u r nt comfortable.......
    much easier way is to format the client system and then installing the addon again.......
    Thanks
    Abhishek

  • Error WLS 10901 - when I add prompt in query from SAP in QAAWS

    Hello,
    I am accessing a Universe who's source is SAP -BEX Query. When I add a charecteristics and key figure I get data, however when I add a prompt or filter condition to my query in QAAWS - I get an error. I tried the same in Live Office and get the same error when I add the prompt  in the query.
    Error: WLS 10901 - getdocument information- A database error occurred - Error in MDData - Get_Leading_Column_data(see long text) --
    Why does this happen when I add a prompt to the query?

    HI Abhi,
    The Issue seem to be not from BO Universe. Can you please go and check the data at Bex report and to apply same condition over there.
    This might help us to track where exactly the error is happening.
    Since the flow is from Cubes to Bex Queries to Universe to QaaWS or Weni Reports.
    So its always better to track the data flow from source. In our scenario its Bex.
    Hope this may help you now and in future.
    Regards,
    AnjaniKumar C.A.

  • How to add selection in Query

    How to add additional fields created  to selection screen too ?
    I have created some additional fields in the infoset . but when i am trying to create a  Query the fields are only appearing as  output fields ...
    normally the fields should appear both as a selection and output field .
    thanks in advance ..
    Naval Bhatt

    Hi,
    Create additional fields in infoset, assign those fields to field group then generate infoset. Change corresponding query where you will see the additional fields and in selection fields window select the additional fields.
    Cheers.
    ...Reward if useful

  • Add table in query.

    Hello experts ,
    I have query with 1 table , if i want to add one more table to my query  and make a join with 2 tables or more than 2 , how can i do this ?
    Thanks for your help,
    Avi.

    hi.
    select kna1~kunnr kna1~sortl zsdo~asmid pa0001~ename
           zsdo~pc_p01_begda zsdo~pc_p01_ded_per
            into corresponding fields of table it_samptb_all
            from zsdo
            inner join kna1 on ( zsdo~kunnr = kna1~kunnr )
            inner join pa0001 on ( zsdo~asmid = pa0001~pernr )
        where zsdo~samp_flag eq 'X'     " Sampling is Active
          and zsdo~ostact = '1'         " Active Outlets only
          and zsdo~pc_p01_cshare ne '0'
          and pa0001~endda eq '99991231'
          and zsdo~ssok in ssok1
          and zsdo~kunnr in kunnr1.

  • Add rows to query result?

    Is it possible to add rows to a SQL query's result, similar to the COMPUTE command in SQL*Plus?
    That is, for example, when the value for column A changes, add a row after the previous row (the last one before column A changed) to show the sum of the values of column B.
    e.g.
    <PRE>A B
    1 3
    1 4
    1 5
    12
    2 9
    2 -1
    2 -7
    1</PRE>

    SQL> create table sales (person,city,sales)
      2  as
      3  select 'Alice', 'Phoenix', 19 from dual union all
      4  select 'Alice', 'Tulsa', 11 from dual union all
      5  select 'Bob', 'Phoenix', 17 from dual union all
      6  select 'Bob', 'Tulsa', 9 from dual union all
      7  select 'Tony', 'Miami', 5 from dual union all
      8  select 'Tony', 'San Francisco', 4 from dual union all
      9  select 'Tony', 'San Francisco', 3 from dual
    10  /
    Tabel is aangemaakt.
    SQL> select case grouping_id(person,city,rowid)
      2         when 1 then 'Sub-Total for'
      3         when 3 then 'Sub-Total for'
      4         when 7 then 'Grand Total'
      5         end notes
      6       , person
      7       , city
      8       , sum(sales) sales
      9    from sales
    10   group by rollup(person,city,rowid)
    11  having grouping_id(city,rowid) != 1
    12      or count(*) > 1
    13   order by person
    14       , city
    15       , grouping(rowid)
    16  /
    NOTES         PERSO CITY               SALES
                  Alice Phoenix               19
                  Alice Tulsa                 11
    Sub-Total for Alice                       30
                  Bob   Phoenix               17
                  Bob   Tulsa                  9
    Sub-Total for Bob                         26
                  Tony  Miami                  5
                  Tony  San Francisco          4
                  Tony  San Francisco          3
    Sub-Total for Tony  San Francisco          7
    Sub-Total for Tony                        12
    Grand Total                               68
    12 rijen zijn geselecteerd.Regards,
    Rob.

  • Add-in Excel - query disconnected

    I installed on a virtual PC :
    - windows server 2003
    - Oracle DB 10.1.0.2
    - Database patch 10.1.0.4
    - Global schema (sample schema for OLAP)
    and I am using Excel Spreadsheet version 10.1.2.0.36 to connect to OLAP cube.
    I can connect to the cube and play with it, but get regulary disconnected with BIA-4018 Error.
    Does anyone knows the cause of this error ?
    Thanks
    Cedric

    I would appreciate some help on the same topic as described above.
    I have installed
    Oracle Database 10g 10.1.0.2.0
    - PatchSet 1 - 10.1.0.3.0
    - BI Common Schema from "BI Samples" (version 10.1.2.0.0_c in version.txt)
    - Interim Patch - Olap Patch for 10.1.0.3.0 (1010310408050001)
    - Oracle ODBC Driver 10.1.0.3.1
    When running Oracle BI Spredasheet Add-In (build 10.1.2.0.36) I open
    samples.xls and connect to my 10g database as CSL_OLAP user,
    connection is successfull but refresh of any query in XLS fails
    with message: BIA-4018 (failed to refresh query).
    I have tried to rename XLS file and reopen it, but error BIA-4018 still appears.
    Also when running from Excel menu under Oracle BI "New Query" wizard, the second screen (after selecting layout) will hang.

  • How to add infoObject at query level

    Dear Friends,
    How to add or import Info Object or Charecterstics directly at query level. Please note that this perticular Info Object is not available in Info Cube.
    Please help me. It is very urgent.
    Regards

    Thanks Mr.Ramana
    I have added InfoObject accordingly in MultiProvider, but in query result no results are coming for this perticular infoobject. It is coming as "Not assigned".
    Is there any other solution like "customer exit"
    Please reply.
    Regards
    Guru

  • Reasons for Add a combined query being grayed out?

    I want to create a combined query but the option is grayed out. This report is a duplicate of an already existing document. I have checked that all the queries in this document are based on the same universe. Are there any other reasons that this may be the case? I have tried creating a document from scratch and the option to combine the queries is available to me.

    Do you perhaps have "scope of analysis" set on the data provider? You can check by counting the number of objects visible on the query panel and then open the SQL and see how many select values there are. I have seen cases where the scope of analysis (which adds extra dimensions to the query in an invisible fashion) interferes with the combine queries option.
    Note that normally you can check the scope by clicking the appropriate button on the query panel toolbar and invoking the scope panel. However, I have seen some cases where objects are in the SQL even without showing up on the scope panel... it's worth a check.

Maybe you are looking for