Require Code which export SQL Query resuluts to excel using checkbox option

Hi All,
I need a sample code which can export the SQL Query results directly to an excel file using checkbox option. for example
if I select checkbox1 and press a save button, then on backend SQL Query will execute and save the results in a excel file and so on.
Thanks in advance..
Regards,
Chetan

Thanks for the Code.
Actually I need a code which is based on combo base values and when I click on Button, the SQL Query will execute using SQL Connection string and the results from that query will save into a excel file. Below is the screenshot of the form. Hope this will
clear the requirements.
Hello,
To be honest, this forum is not for coding for anybody.
You could refer to the suggestions shared above, and if you get any issue when using that code, you could share the code and error with us, we will focus on your code to help you.
You could separate them into multiple steps, like the following.
1. Getting the value of any control, like the textbox and combobox or even checkbox.
2. Execute method inside button click event handler.
3. Using ado.net to execuate sql query.
4. Saving data to Excel.
Then you could have a try step by step, if you get any issue, then post it in another thread with the code and error message.
Regards,
Carl
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Error while calling the function which returns SQL Query!!!

    Hi,
    I have a Function which returns SQL query. I am calling this function in my APEX report region source.
    The query is dynamic SQL and its size varies based on the dynamic "where clause" condition.
    But I am not able to execute this function.It gives me the following error in APEX region source.
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Even in SQL* Plus or SQL developer also same error .
    The length of my query is more than 4000. I tried changing the variable size which holds my query in the function.
    Earlier it was
    l_query varchar2(4000)
    Now I changed to
    l_query varchar2(32767).
    Still it is throwing the same error.
    Can anybody help me to resolve this.???
    Thanks
    Alaka

    Hi Varad,
    I am already using 32k of varchar2. Then also it is not working.
    It is giving the same error. I think there is something to do with buffer size.
    My query size is not more than 4200. Even if i give 32k of varchar2 also buffer is able to hold only 3997 size of the query only.
    Error is
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Tried CLOB also. It is not working.
    Any other solution for this.
    Thanks
    Alaka

  • Is it possible to write an abap code be SAP SQL query.(ECC 6)

    hello guys,
    Is it possible to write an abap code be SAP SQL query.
    Scenario : table A has a field say f1 of length 10 and table B has a field say s1 of lenght 20. in sap sql i am able to link all the other tables but i am not able to link
    table Af1 --->Table Bs1. as the length doesnot match. so is it possibel that using abap code I can pick 10 characters from table A field f1 adjust it to 20 characters using abap and map it to field s1 of table B.
    Please let me know how to accomplish this if possible.
    thanks in advance!!

    Herm,
    Adding code is done in the infoset.
    Please do following:
    > Goto SQ02
    > Type in the infoset that the basis for your query, <change>
    > Press <code> OR <shift><f8>
    > Tou'll see 4 tabs: Extras, Selections, Code, Enhancements.
    > GoTo tab Code
    > Choose the coding section (<f4> gives you an overview)
    > Enter the code.
    You may set a breakpoint to see what the query in SQ01 will do with it.
    Succes!
    Frank

  • Saving sql query result as excel file in different spreadsheets

    Hi,
    I have exported the output of sql into excel sheet as follow:
    SET LINESIZE 80
    SET PAGESIZE 0
    SET FEEDBACK OFF
    SET SPOOL ON
    SET TERMOUT OFF
    SPOOL current_employees.csv
    SELECT '"ID","Sales Amount","Region Id","Sales Date"' FROM dual;
    set colsep ,
    SELECT * FROM sales;
    SPOOL OFF
    But my question is how can I export SQL output in multiple excel spredsheets?
    Is there anything by which I can switch my spreadsheets through the above SQL script?
    Regards,
    Ashish

    Hi,
    I have exported the output of sql into excel sheet as follow:
    SET LINESIZE 80
    SET PAGESIZE 0
    SET FEEDBACK OFF
    SET SPOOL ON
    SET TERMOUT OFF
    SPOOL current_employees.csv
    SELECT '"ID","Sales Amount","Region Id","Sales Date"' FROM dual;
    set colsep ,
    SELECT * FROM sales;
    SPOOL OFF
    But my question is how can I export SQL output in multiple excel spredsheets?
    Is there anything by which I can switch my spreadsheets through the above SQL script?
    Regards,
    Ashish

  • Export SQL query from link or button

    I want to list several 'canned' SQL queries on one page as buttons or links; and have the result of selection be an immediate extract/download to excel of the data.
    How can I best do this?
    I suppose I could create separate hidden regions with their own reports that could somehow be referenced in the link. I would like to avoid doing all that, if I can create a package or process that includes the SQL query and that can be called in the link.
    Thanks in advance,
    Rich
    Edit:
    Found 'Report Query' functionality in Apex v3.2.1: However I am unable to get this to work; tells me my printer is not set up. I don't want to print the detail, I want it to be downloaded into excel... I don't have a printer configured - & don't want to. The URL provided for download as attachment is:
    f?p=&APP_ID.:0:&SESSION.:PRINT_REPORT=reportname
    I also have no page 0.
    Help?
    Edited by: rdarlin2 on Sep 16, 2011 11:14 AM

    rdarlin2 wrote:
    I want to list several 'canned' SQL queries on one page as buttons or links; and have the result of selection be an immediate extract/download to excel of the data.
    How can I best do this?
    I suppose I could create separate hidden regions with their own reports that could somehow be referenced in the link. I would like to avoid doing all that, if I can create a package or process that includes the SQL query and that can be called in the link.10,000ft overview of one way to do this:
    <li>Create a package with private functions that return the SQL for each "canned query", and a public switch function that returns a query function based on an input parameter:
    create or replace package qry
    is
      function selector (p_req_qry in varchar2) return varchar2;
    end qry;
    create or replace package body qry
    is
      function emp_qry return varchar2
      is
      begin
        return 'select * from emp';
      end emp_qry;
      function dept_qry return varchar2
      is
      begin
        return 'select * from dept';
      end dept_qry;
      function selector (p_req_qry in varchar2) return varchar2
      is
      begin
        return
          case p_req_qry
            when 'EMP' then emp_qry()
            when 'DEPT' then dept_qry()
          end;
      end selector;
    end qry;
    /<li>Create 2 pages
    <li>On page 2 create a standard SQL report region of type SQL Query (PL/SQL function body returning SQL query):
    Region Source
    return qry.selector(:request);*(o) Use Generic Column Names (parse query at runtime only)*
    Maximum number of generic report columns
    number of columns in your biggest query
    Report Template
    export: CSV
    <li>On page 1 create an HTML region (or use an APEX list) with a link for each query, where the REQUEST component of the URL is the parameter used to select a query in the <tt>qry.selector</tt> function:
    <ul>
      <li>&lt;a href="f?p=&APP_ID.:2:&SESSION.:EMP"&gt;Emp</a></li>
      <li>&lt;a href="f?p=&APP_ID.:2:&SESSION.:DEPT"&gt;Dept</a></li>
    </ul>However this begs the question: Why bother? What's Excel got that APEX hasn't?

  • Need sql query to remove duplicates using UNION ALL clause

    Hi,
    I have a sql query which has UNION clause.But the UNION clause is causing some performance issues.
    To overcome that I have used UNION ALL to improve performance but its returning duplicates.
    Kindly anyone send a sample SQL query where my primary objective is used to use UNION ALL clause and to consider unique rows (elimating duplicate
    ones)
    Any help will be needful for me
    Thanks and Regards

    why not UNION? :(
    another way also use MINUS
    SQL>
    SQL> with t as
      2  (
      3  select 1 if from dual union all
      4  select 2 if from dual union all
      5  select 1 if from dual union all
      6  select 3 if from dual union all
      7  select 3 if from dual
      8  )
      9  ,t2 as
    10  (
    11  select 1 if from dual union all
    12  select 2 if from dual union all
    13  select 3 if from dual union all
    14  select 4 if from dual union all
    15  select 5 if from dual
    16  )
    17  (select if from t
    18  union all
    19  select if from t2)
    20  /
            IF
             1
             2
             1
             3
             3
             1
             2
             3
             4
             5
    10 rows selected
    SQL> so
    SQL>
    SQL> with t as
      2  (
      3  select 1 if from dual union all
      4  select 2 if from dual union all
      5  select 1 if from dual union all
      6  select 3 if from dual union all
      7  select 3 if from dual
      8  )
      9  ,t2 as
    10  (
    11  select 1 if from dual union all
    12  select 2 if from dual union all
    13  select 3 if from dual union all
    14  select 4 if from dual union all
    15  select 5 if from dual
    16  )
    17  (select if from t
    18  union all
    19  select if from t2)
    20  minus
    21  select -99 from dual
    22  /
            IF
             1
             2
             3
             4
             5
    SQL>

  • Exporting a query report in Excel gives a wrong value.

    Hi All,
    After running the query report, from the menu path, I do List > Export > Spreadsheet.  At that point, you can save the file and Excel opens up.  The value for the amount are displaying with additional zeroes
    For example 14,000.00  is dispalyed as 14,000,00.00
    Please let me know the if you have solution for this are related OSS note for this
    Thanks,
    Karthikeyan.

    Hi David,
    Thanks for your response.
    The OSS notes are related to ALV display where when i check with other ALV program and export it is giving a correct total.Where when i download the qurey report in excel using file-> export to option i am getting  a additional zeroes.
    Please let me know if there is any other solution for this.
    Thanks for your help in advance.
    Thanks,
    Karthikeyan.

  • How to capture a parameter value in SQL QUERY of scale marker using GO URL

    Hi,
    Can any one please tell me how to capture the parameter value from go url inside Where clause of Scale Marker.
    I am trying to sift the position of scale marker based on SQL Query.
    Thanks-Bhaskar Gouda.
    Edited by: 961171 on Sep 25, 2012 12:33 AM

    Since this is a synchronous interface, where source is a soap(proxy) call and target is JDBC in the first mapping both of them are request scenarios.
    Source Structure:
    RootNode
        Request             1...unbounded
           No_of_Days   1.1 String
    Target Structure:
    RootNode
       Statement
         TableName
             Action mapped to SQL_QUERY
            Access -  SELECT DISTINCT AL.EC_NO,DP.DATE_TO_FORMAL FROM T_APPLICATION_LIST AL,(SELECT DE.EC_NO AS "EC_NO", DE.PACKAGE_NO AS "PACKAGE_NO",PC.DATE_TO_FORMAL AS "DATE_TO_FORMAL" FROM DAICYO_ECNO DE,PACKAGECTL PC WHERE DE.PACKAGE_NO = PC.PACKAGE_NO AND PC.DATE_TO_FORMAL > (TRUNC(SYSDATE) - to_number('$No_Of_DAYS$'))) DP WHERE AL.EC_NO IN  (SELECT EC_NO FROM DAICYO_ECNO WHERE PACKAGE_NO IN (SELECT PACKAGE_NO FROM PACKAGECTL WHERE DATE_TO_FORMAL > (TRUNC(SYSDATE) - to_number('$No_Of_DAYS$')))) AND (AL.FAMILY = ''  or  '' is null and AL.FAMILY is not null ) and DP.EC_NO = AL.EC_NO ORDER BY DATE_TO_FORMAL
         Key
          No_Of_Days   1..1 String
    In Return I am expecting a JDBC response from the Oracle Database as:
    Source Structure:
    RootNode
      STATEMENT_response   1...unbounded
         row                               0...undbounded
           EC_NO                        1..1   String
    Target Structure:
    RootNode
      RESPONSE
        row
         EC_NO                     1..1     String

  • Export a datagrid to an excel using com.as3xls.xls.Sheet class

    I am trying to export a datagrid to an excel in Flex using com.as3xls.xls.Sheet class. But the contents of the cells in the excel are overlapping so I need to wordwrap the cells and also change the width of the cells. How can I do that in flex?

    You can use flexspreadsheet for this purpose.
    The excel file exported from Flexspreadsheet is well formatted and wordwrap supported than as3xls.
    here is a link that can help you.
    Thanks,
    Kanchan | www.infocepts.com

  • Error in Exporting HRMS people data to excel using WEB EDI.

    Hi ,
    I am using an existing integrator to export people data to excel using WEB ADI.
    When the excel opens it first shows the it is trying to download data, but later shows an error message saying that an error has occurred in the script on this page
    line 18
    Char 5
    Error Object doesn't support this property or method.
    Can anyone please throw some light as to what can be the cause of the error.
    Regards
    Deepak

    Hi experts,
    When I click the "Upload" button on GL Journal WebADI, The following error message is displayed:
    http://myservername:port/OA_HTML/BneApplicationService?bne:encoding=UTF-8
    I think this error is similar as your previous discussion, and I tried the solution as you mentioned, but not worked. If there is any new solution for the errors of this kind?
    Some Environment parameters are as following:
    Product: EBS 12.1.1
    Browser: IE 7.0 and Firefox 3.5.5
    Hope for your advice.
    Thanks in advance.

  • FS - Error code 3006 from SQL-Query

    Hello world!
    Can someone inform me which possible errors in a query cause the following error message after the query is activated?
    Internal Error (3006) Message [131-183]
    Until now I had only error code 1003, which signals syntax errors etc. in the query.
    By the way: Does anywhere exists a list of error codes/messages occuring in SAP B1?
    Thank you!
    Frank Romeni

    Error codes and their description can be found in SDK help files
    I have pasted them below for your ref
    -39
    End of File
    -43
    File not Found
    -47
    File is Busy
    -50
    File Cannot Open
    -51
    File Corrupted
    -99
    Division by Zero
    -100
    Out of Memory
    -101
    Print Error
    -103
    Print Canceled
    -104
    Money Overflow
    -111
    Invalid Memory Access
    -199
    General Error
    -213
    Bad Directory
    -214
    File Already Exists
    -216
    Invalid File Permission
    -217
    Invalid Path
    -1001
    Data Source - Bad Column Type
    -1003
    Data Source - Alias Not Found
    -1004
    Data Source - Value Not Found
    -1005
    Data Source - Bad Date
    -1012
    Data Source - No Default Column
    -1013
    Data Source - Zero/Blank Value
    -1015
    Data Source - Integer Overflow
    -1016
    Data Source - Bad Value
    -1022
    Data Source - Other File Not Related
    -1023
    Data Source - Other Key Not In Main Key
    -1025
    Data Source - Array Record Not Found
    -1027
    Data Source - Value Must Be Positive
    -1028
    Data Source - Value Must Be Negative
    -1029
    Data Source - Column Cannot be updated
    -1100
    Data Source - Cannot Allocate Environment
    -1101
    Data Source - Bad Connection
    -1102
    Data Source - Connection Not Opened
    -1103
    Data Source - DB Already Exists
    -1104
    Data Source - Cannot Create Database
    -1200
    Data Source - Data Bind General Error
    -2001
    Data Source - Bad Parameters
    -2003
    Data Source - Too Many Tables
    -2004
    Data Source - Table Not Found
    -2006
    Data Source - Bad Table Definition
    -2007
    Data Source - Bad Data Source
    -2010
    Data Source - Bad Data Source Offset
    -2013
    Data Source - No Fields In Table
    -2014
    Data Source - Bad Field Index
    -2015
    Data Source - Bad Index Number
    -2017
    Data Source - Bad Alias
    -2020
    Data Source - Bad Alias
    -2022
    Data Source - Bad Field Level
    -2024
    Data Source - Not Matching Data Source
    -2025
    Data Source - No Keys In Table
    -2027
    Data Source - Partial Data Found
    -2028
    Data Source - No Data Found
    -2029
    Data Source - No Matching Field
    -2035
    Data Source - Duplicate Keys
    -2038
    Data Source - Record Lock
    -2039
    Data Source - Data Was Changed
    -2045
    Data Source - End of Sort
    -2049
    Data Source - Not Opened for Write
    -2056
    Data Source - No Matching With Current Data Source
    -2062
    Data Source - Bad Container Offset
    -3001
    Query - Field Not Found
    -3003
    Query - Bad Data Source
    -3004
    Query - Bad Token
    -3005
    Query - Token After End
    -3006
    Query - Unexpected End
    -3008
    Query - Too Long Query
    -3009
    Query - Extra Right Parenthesis
    -3010
    Query - Missing Right Parenthesis
    -3012
    Query - No Operation Code
    -3013
    Query - No Field In Comparison
    -3014
    Query - Bad Condition
    -3015
    Query - Bad Sort List
    -3017
    Query - No String
    -3018
    Query - Too Many Fields
    -3019
    Query - Too Many Indexes
    -3020
    Query - Too Many Tables
    -3021
    Query - Reference Not Found
    -3022
    Query - Bad Range Set
    -3023
    Query - Bad Parsing
    -3025
    Query - Data Bind is Missing
    -3026
    Query - Bad Input
    -3027
    Query - Progress Aborted
    -3028
    Query - Bad Table Index
    -3032
    Query - General Failure
    -3033
    Query - Empty Record
    -3036
    Query - Bad Parameter
    -3037
    Query - Missing Table in List
    -3040
    Query - Bad Operation
    -3041
    Query - Bad Expression
    -3042
    Query - Name Already Exists
    -3044
    Query - Time Expired
    3001
    Form - Is Not Initialized
    3002
    Form - Bad Data Source
    3003
    Form - Exceeded Data Sources Limit
    3006
    Form - Invalid Form Item
    3007
    Form - Exceeded Forms Limit
    3009
    Form - Too Many Saved Data
    3012
    Form - Invalid Form
    3015
    Form - Cannot Get Multi-Line Edit
    3016
    Form - Bad Item Type
    3017
    Form - Bad Parameter
    3023
    Form - No Message Callback
    3029
    Form - Item Is Not Selectable
    3031
    Form - Bad Value
    3033
    Form - Item Not Found
    4007
    Grid - Invalid
    4008
    Grid - Bad Size
    4009
    Grid - No Data
    4011
    Grid - Invalid Parameters
    4013
    Grid - Not Super Title
    4014
    Grid - Super Title 2 Exits
    4015
    Bad Item Unique ID
    4016
    Grid - Bad Data
    4017
    Grid - Column is Already Folded
    4018
    Grid - Column is Already Expanded
    4019
    Grid - Line Exists
    4020
    Grid - Not Enough Data
    4022
    Grid - Super Title Exists
    4027
    Grid - Row Is Not Collapsible
    8004
    Status Bar - No Such Info
    8005
    Status Bar - Info Occupied
    8006
    Status Bar - No Message Bar
    8007
    Status Bar - Progress Stopped
    8008
    Status Bar - Too Many Progress
    5001
    Graph - Invalid
    5002
    Graph - Bad Form Item
    5005
    Graph - Bad Parameters
    -7008
    Form not found
    -7000
    Invalid Form
    -7031
    Form - Reserved /Illegal form Unique ID
    -7032
    Form - Invalid Mode
    -7006
    The item is not a user defined item and cannot be manipulated in such manner
    -7005
    Invalid table name
    -7004
    XML batch load failed
    -7003
    Menu operation Add failed
    -7002
    Function not supported
    -7001
    Invalid Item
    -7034
    Could not clear item in group
    -7033
    Out of boundaries
    -7020
    This method cannot be invoked by a Cell object
    -7019
    Invalid form unique ID. Should not begin with an F_ prefix
    -7018
    Invalid Field Value
    -7017
    Invalid Field Name
    -7016
    This datasource object is not a user-defined object
    -7015
    Invalid Column
    -7014
    A Column object with the specified unique ID already exists in the system.
    -7013
    The string value entered should be less then 10 characters.
    -7012
    An Item object with the specified unique ID already exists in the system.
    -7011
    The string value entered should be less then 11 characters.
    -7010
    A form with the requested unique ID already exists in the system.
    -7009
    The string value entered should be less the 32 characters.
    -7040
    Cannot Load XML File
    -7051
    Unexpected usage of the specified XML TAG.
    -7050
    This action type is not valid or not implemented yet.
    -7043
    Cannot load the Menu resource from the specified XML file.
    -7042
    Cannot load the Item resource from the specified XML file.
    -7041
    Cannot load the Form resource from the specified XML file.
    -7071
    Failed to create the items group.
    -7070
    UID
    -7069
    Failed to change the form current pane level.
    -7068
    Failed to change the form color.
    -7067
    Failed to change the Form mode.
    -7066
    Failed to fix the form default button.
    -7065
    Failed to change the form Visible state.
    -7064
    Could not change the form title.
    -7063
    The change of form dimensions has failed
    -7062
    Unknown Form attribute
    -7061
    XML batch resource update is not supported yet.
    -7060
    Reached Max Number of user data sources.
    -7094
    Failed to add the items child objects.
    -7093
    Failed to batch add the items
    -7092
    Failed to bind the item to the data source
    -7091
    Wrong Item Attribute
    -7090
    Unknown Field Type
    -7114
    Type of Column is Not Supported.
    -7113
    Failed to add the column child objects.
    -7112
    Failed to add the new columns.
    -7111
    Failed to bind the column to a data source
    -7110
    Invalid column attributes
    -7133
    The specified menu position is not valid
    -7132
    Invalid menu type
    -7131
    Failed to add the menu object
    -7130
    The specified menu already exists.
    -7030
    Invalid Row Number
    -7029
    Operation not supported on system form.
    -7028
    Out of boundary of DB data source offset.
    -7027
    The menu item is not a user defined menu item and cannot be manipulated in such manner.
    -7026
    Menu item was not found
    -7025
    Unknown Form State
    -7024
    Failed setting form bounds
    -7023
    Invalid Target
    -7022
    Could not commit action because the item is currently in focus.
    -7021
    Operation could not be set on extended edit text item.
    -7200
    Your connection string doesn't much UI development work mode.
    -7201
    The specified connection string is not valid.

  • WRH$** tables, Need to know by which user SQL Query has been executed

    Hi,
    From the AWR data (WRH$) tables , I need to know how many sql code is using some specific indexes, I found that information by using the mentioned code. but I need to find out by which user this code has been executed ( not the PARSING_SCHEMA_NAME). Can someone please help me, how can I get that info?
    select a.operation,a.OBJECT_OWNER,a.OBJECT_NAME ,dbms_lob.substr(b.SQL_TEXT,4000,1) from WRH$_SQL_PLAN a,WRH$_SQLTEXT b
    where a.operation='INDEX' and a.SNAP_ID=b.SNAP_ID and a.SQL_ID=b.SQL_ID and a.OBJECT_NAME in (
    'I_CUSTORDER_STAT_CHG_DTM',
    'I_LINE_ITEM_STAT_CHG_DTM',
    'I_SHOPCART_MODIFIEDDTM',
    'I_VISITOR_CART_UPDATED_DTM',
    'R_ORDER_LOG_EVENT_DTM',
    'I_LI_STATUS_HISTORY_EVENT_DTM',
    'I_SHOPPING_CART_CREATEDDTM',
    'I_VISITOR_CART_CREATED_DTM',
    'I_LINE_ITEM_CREATED_DTM_FTM')

    872903 wrote:
    Hi,
    From the AWR data (WRH$) tables , I need to know how many sql code is using some specific indexes, I found that information by using the mentioned code. but I need to find out by which user this code has been executed ( not the PARSING_SCHEMA_NAME). Can someone please help me, how can I get that info?
    select a.operation,a.OBJECT_OWNER,a.OBJECT_NAME ,dbms_lob.substr(b.SQL_TEXT,4000,1) from WRH$_SQL_PLAN a,WRH$_SQLTEXT b
    where a.operation='INDEX' and a.SNAP_ID=b.SNAP_ID and a.SQL_ID=b.SQL_ID and a.OBJECT_NAME in (
    'I_CUSTORDER_STAT_CHG_DTM',
    'I_LINE_ITEM_STAT_CHG_DTM',
    'I_SHOPCART_MODIFIEDDTM',
    'I_VISITOR_CART_UPDATED_DTM',
    'R_ORDER_LOG_EVENT_DTM',
    'I_LI_STATUS_HISTORY_EVENT_DTM',
    'I_SHOPPING_CART_CREATEDDTM',
    'I_VISITOR_CART_CREATED_DTM',
    'I_LINE_ITEM_CREATED_DTM_FTM')consider enabling AUDIT SELECT FROM TABLE upon which INDEX is based.

  • ABAP Code for the SQL Query

    Hi,
    I am a BASIS person.
    I need to create an ABAP program which willl return the <b>count</b> of rows returned by the following query.Pls help me in this
    <b>SELECT AGR_NAME FROM AGR_1250 where OBJECT IN (select OBJCT from
    TOBJ where OCLSS IN ('RS','RSR','RSBC')) AND
    AGR_NAME LIKE 'Z%'</b>
    Message was edited by:
            Balaji R

    hi, Balaji,
    TABLES: ekpo, ekko.
    DATA: BEGIN OF itab1 OCCURS 0,
    ebeln LIKE ekpo-ebeln,
    ebelp LIKE ekpo-ebelp,
    matnr LIKE ekpo-matnr,
    END OF itab1.
    DATA: BEGIN OF itab2 OCCURS 0,
    ebeln LIKE ekko-ebeln,
    lifnr LIKE ekko-lifnr,
    bukrs LIKE ekko-ebeln,
    END OF itab2.
    DATA: count LIKE sy-dbcnt.
    DATA: BEGIN OF itab3 OCCURS 0,
    ebeln LIKE ekpo-ebeln,
    ebelp LIKE ekpo-ebelp,
    matnr LIKE ekpo-matnr,
    lifnr LIKE ekko-lifnr,
    bukrs LIKE ekko-bukrs,
    END OF itab3.
    SELECT-OPTIONS: s_ebeln FOR ekpo-ebeln.
    SELECT ebeln ebelp matnr INTO TABLE itab1 FROM ekpo
    WHERE ebeln IN s_ebeln.
    IF NOT itab1[] IS INITIAL.
      SELECT ebeln lifnr bukrs INTO TABLE itab2 FROM ekko
      FOR ALL ENTRIES IN itab1
      WHERE ebeln = itab1-ebeln.
    count = sy-dbcnt.
    ENDIF.
    LOOP AT itab1.
      READ TABLE itab2 WITH KEY
             ebeln = itab1-ebeln.
      itab3-ebeln = itab1-ebeln.
      itab3-ebelp = itab1-ebelp.
      itab3-matnr = itab1-matnr.
      itab3-lifnr = itab2-lifnr.
      itab3-bukrs = itab2-bukrs.
      APPEND itab3.
    ENDLOOP.
    LOOP AT itab3.
      WRITE : / sy-vline,
                itab3-ebeln, sy-vline,
                itab3-ebelp, sy-vline,
                itab3-matnr, sy-vline,
                itab3-lifnr, sy-vline,
                itab3-bukrs, sy-vline.
    ENDLOOP.
    write : count.
    <b>
    Regards,
    Azhar</b>

  • How to export sql table data to Excel/PDf using Storedprocedure?

    Hi ,
            I have one table in sqlserver2008R2 that named "Customer" so that table hold the 1 Lac rows. Now I want send this table data to Excel/pdf with Columns using Storedprocedure.
       I have tried this using xp_cmdshell so This is not working for me.
    finally i want to get data in Excel and pdf also.
    Please guide me

    You can actually run an Excel Macro to grab the data from the SQL Server DB.  Below are some samples.
    Sub ADOExcelSQLServer()
    ' Carl SQL Server Connection
    ' FOR THIS CODE TO WORK
    ' In VBE you need to go Tools References and check Microsoft Active X Data Objects 2.x library
    Dim Cn As ADODB.Connection
    Dim Server_Name As String
    Dim Database_Name As String
    Dim User_ID As String
    Dim Password As String
    Dim SQLStr As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Server_Name = "Excel-PC\SQLEXPRESS" ' Enter your server name here
    Database_Name = "Northwind" ' Enter your database name here
    User_ID = "" ' enter your user ID here
    Password = "" ' Enter your password here
    SQLStr = "SELECT * FROM dbo.Orders" ' Enter your SQL here
    Set Cn = New ADODB.Connection
    Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
    ";Uid=" & User_ID & ";Pwd=" & Password & ";"
    rs.Open SQLStr, Cn, adOpenStatic
    ' Dump to spreadsheet
    With Worksheets("sheet1").Range("a1:z500") ' Enter your sheet name and range here
    .ClearContents
    .CopyFromRecordset rs
    End With
    ' Tidy up
    rs.Close
    Set rs = Nothing
    Cn.Close
    Set Cn = Nothing
    End Sub
    Sub ADOExcelSQLServer()
    Dim Cn As ADODB.Connection
    Dim Server_Name As String
    Dim Database_Name As String
    Dim User_ID As String
    Dim Password As String
    Dim SQLStr As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Server_Name = "LAPTOP\SQL_EXPRESS" ' Enter your server name here
    Database_Name = "Northwind" ' Enter your database name here
    User_ID = "" ' enter your user ID here
    Password = "" ' Enter your password here
    SQLStr = "SELECT * FROM Orders" ' Enter your SQL here
    Set Cn = New ADODB.Connection
    Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
    ";Uid=" & User_ID & ";Pwd=" & Password & ";"
    rs.Open SQLStr, Cn, adOpenStatic
    With Worksheets("Sheet1").Range("A2:Z500")
    .ClearContents
    .CopyFromRecordset rs
    End With
    rs.Close
    Set rs = Nothing
    Cn.Close
    Set Cn = Nothing
    End Sub
    Sub TestMacro()
    ' Create a connection object.
    Dim cnPubs As ADODB.Connection
    Set cnPubs = New ADODB.Connection
    ' Provide the connection string.
    Dim strConn As String
    'Use the SQL Server OLE DB Provider.
    strConn = "PROVIDER=SQLOLEDB;"
    'Connect to the Pubs database on the local server.
    strConn = strConn & "DATA SOURCE=(local);INITIAL CATALOG=NORTHWIND.MDF;"
    'Use an integrated login.
    strConn = strConn & " INTEGRATED SECURITY=sspi;"
    'Now open the connection.
    cnPubs.Open strConn
    ' Create a recordset object.
    Dim rsPubs As ADODB.Recordset
    Set rsPubs = New ADODB.Recordset
    With rsPubs
    ' Assign the Connection object.
    .ActiveConnection = cnPubs
    ' Extract the required records.
    .Open "SELECT * FROM Categories"
    ' Copy the records into cell A1 on Sheet1.
    Sheet1.Range("A1").CopyFromRecordset rsPubs
    ' Tidy up
    .Close
    End With
    cnPubs.Close
    Set rsPubs = Nothing
    Set cnPubs = Nothing
    End Sub
    Finally, you can run a SProc in SQL Server, from Excel, if you want the SProc to do the export.
    Option Explicit
    Sub Working2()
    'USE [Northwind]
    'GO
    'DECLARE @return_value int
    'EXEC @return_value = [dbo].[TestNewProc]
    ' @ShipCountry = NULL
    'SELECT 'Return Value' = @return_value
    'GO
    Dim con As Connection
    Dim rst As Recordset
    Dim strConn As String
    Set con = New Connection
    strConn = "Provider=SQLOLEDB;"
    strConn = strConn & "Data Source=LAPTOP\SQL_EXPRESS;"
    strConn = strConn & "Initial Catalog=Northwind;"
    strConn = strConn & "Integrated Security=SSPI;"
    con.Open strConn
    'Put a country name in Cell E1
    Set rst = con.Execute("Exec dbo.TestNewProc '" & ActiveSheet.Range("E1").Text & "'")
    'The total count of records is returned to Cell A5
    ActiveSheet.Range("A5").CopyFromRecordset rst
    rst.Close
    con.Close
    End Sub
    Sub Working()
    'USE [Northwind]
    'GO
    'DECLARE @return_value int
    'EXEC @return_value = [dbo].[Ten Most Expensive Products]
    'SELECT 'Return Value' = @return_value
    'GO
    Dim con As Connection
    Dim rst As Recordset
    Set con = New Connection
    con.Open "Provider=SQLOLEDB;Data Source=LAPTOP\SQL_EXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI;"
    Set rst = con.Execute("Exec dbo.[Ten Most Expensive Products]")
    'Results of SProc are returned to Cell A1
    ActiveSheet.Range("A1").CopyFromRecordset rst
    rst.Close
    con.Close
    End Sub
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • Sql query for running sum(using aggregate)

    <pre>
    Table name table1 (no, amount)
    insert into table1 values(1, 10) ;
    insert into table1 values(2 ,-10) ;
    insert into table1 values(3, -20) ;
    insert into table1 values(4,  -30) ;
    insert into table1 values(5,40) ;
    and i am expecting the result in this manner
    no
    sum (amount)
    1
    10
    2
    0
    3
    -20
    4
    -50
    5
    -10
    select no,sum(amount) over(order by no) from table1;
    but with this query i am getting the result in below manner
    no
    sum (amount)
    1
    10
    2
    20
    3
    40
    4
    70
    5
    110
    which is not excepted result, could some one help me in getting excepted results ,could any one provide the proper query for this
    </pre>

    h
    Hi Friends,
    sorry to trouble you,i did  not have oracle instance installed on my machine to check the query ,
    this is some test query which is some resemblance with actual query in my project
    actually the requirement is like this ,this is the master table 
      NO                            amount
             1                         10
             2                         100
             3                         120
             4                         50
             5                         41
    using some decoding function in the query the result came like this
    NO                        decode(amount,......) quantity
             1                          10
             2                         -10
             3                         -20
             4                         -30
             5                          41
    on this decode function i am trying to using aggregate function SUM,but in that case in stood of giving
    ABS value , it is giving   in proper value like below result
      NO        decode(amount,......) quantity    aggregate sum
             1                          10                10
             2                         -10                20
             3                         -20                40
             4                         -30                70
             5                          41                111
    but i excepted the result  ABS  value like below
       NO           decode(amount,......) quantity    aggregate sum
             1                         10                 10
             2                         -10                0
             3                         -20               -20
             4                         -30               -50
             5                          41                -9
       my question is aggregate function on this decoded values have any impact on the result?
       for this question your are unable to help me ,tomorrow i will get exact table structure and exact query which i am using
       in my project

Maybe you are looking for

  • Blue skies turn gray.

    I wonder if anyone can check this behavior in CS3. I noticed that simply applying the Magic Bullet Looks effect, without ever opening the Looks Builder and making any adjustments, that my blue skies turn gray. Viewing on a calibrated, external NTSC m

  • Anyone gotten a self encoded H.264 video to work yet?

    I'd like to know if anyone out there has been able to successfully play a video encoded with H.264 that you encoded yourself (not from the music store) I've only been able to get MPEG4 videos to work, even when I set the encoding options identical to

  • Netting of GL in F.01

    Hiii guru's, How to do netting of GL in F.01 report. In F.01 we get GL P & L statement.i want  total of group of GLs.  System should not show individual GLs. Total of the Group should appear. Subcontracting group.           GL XXXXX         1111     

  • Use of new external drive

    I just bought an external dual-layer burner (with a firewire connection) and have it hooked up to my eMac, which has an internal single-layer superdrive. I want to burn dual-layer DVDs using this new drive, but I can't find anything in the DVD Studio

  • ECATT - Help help help

    Hi, It's 1 month that I try to create an e-catt like old SCAT .. but as you can see I'm not still be able  ..... I'd like to create a test case related to a SAP transaction, I'd simply like to change the vendor name (FK02), data to be changed should