How to build an SQL Query to print Week ranges of a Month

Hi Gurus!!
I have a requirement to create a query to display the Week periods of a month.
The inputs will be Year and month.
The result should be some thing like this:
If Year = 2009 and Month = June
The SQL Query should return the following:
01-Jun-2009 to 06-Jun-2009
07-Jun-2009 to 13-Jun-2009
14-Jun-2009 to 20-Jun-2009
21-Jun-2009 to 27-Jun-2009
27-Jun-2009 to 30-Jun-2009
I am confused how to do this. Please help me. Any help would be grately Appreciated.
Thanks
Ahmed

This is how My Final Query Looks Like:
SELECT TO_CHAR(SYSDATE+7*(level-1),'DD-MON-RRRR')
||' to '
||TO_CHAR(SYSDATE+7*(level-1)+6,'DD-MON-RRRR') RANGES
FROM dual
connect by level<=5
--Ahmed                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to get physical SQL query

    Hi All,
    How to get the physical SQL query for the OBIEE reports.
    Thanks in advance,
    Haree.

    Hi Anitha,
    Thanks for your reply,
    I am getting XML script in log file. (Settings > Administration > Manage Sessions > View Log).
    How to get physical SQL query ?
    Thanks,
    Haree

  • How to tune past SQL query??

    Hi Team,
    Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
    I am working on 10.2.0.4 version DB..
    How to trace an sql query after its execution?? pls provide steps how to begin with..
    regards
    dkoracle

    dkoracle wrote:
    Hi Team,
    Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
    I am working on 10.2.0.4 version DB..
    How to trace an sql query after its execution?? pls provide steps how to begin with..Can not be done.
    ALTER SESSION SET SQL_TRACE=TRUE;
    -- run query again

  • How to view the sql query?

    hi,
      how to view the sql query formed from the xml structure in the receiver jdbc?

    You can view SAP Note at
    http://service.sap.com/notes
    But you require SMP login ID for this which you should get from your company. The content of the notes are as follows:
    Reason and Prerequisites
    You are looking for additional parameter settings. There are two possible reasons why a feature is available via the "additional parameters" table in the "advanced mode" section of the configuration, but not as documented parameter in the configuration UI itself:
    Category 1: The parameter has been introduced for a patch or a SP upgrade where no UI upgrade and/or documentation upgrade was possible. In this case, the parameter will be moved to the UI and the documentation as soon as possible. The parameter in the "additional parameters" table will be deprecated after this move, but still be working. The parameter belongs to the supported adapter functionality and can be used in all, also productive, scenarios.
    Category 2. The parameter has been introduced for testing purposes, proof-of-concept scenarios, as workaround or as pre-released functionality. In this case, the parameter may or may not be moved to the UI and documentation, and the functionality may be changed, replaced or removed. For this parameter category there is no guaranteed support and usage in productive scenarios is not supported.
    When you want to use a parameter documented here, please be aware to which category it belongs!
    Solution
    The following list shows all available parameters of category 1 or 2. Please note:
    Parameter names are always case-sensitive! Parameter values may be case-sensitive, this is documented for each parameter.
    Parameter names and values as documented below must be used always without quotaton marks ("), if not explicitly stated otherwise.
    The default value of a parameter is always chosen that it does not change the standard functionality
    JDBC Receiver Adapter Parameters
    1. Parameter name: "logSQLStatement"
                  Parameter type: boolean
                  Parameter value: true for any string value, false only for empty string
                  Parameter value default: false (empty String)
                  Available with: SP9
                  Category: 2
                  Description:
                  When implementing a scenario with the JDBC receiver adapter, it may be helpful to see which SQL statement is generated by the JDBC adapter from the XI message content for error analysis. Before SP9, this can only be found in the trace of the JDBC adapter if trace level DEBUG is activated. With SP9, the generated SQL statement will be shown in the details page (audit protocol) of the message monitor for each message directly.
                  This should be used only during the test phase and not in productive scenarios.
    Regards,
    Prateek

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • How to write a SQL query in SAP B1 2007 B with input parameters?

    How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?

    The syntax like
    SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
    Thanks,
    Gordon

  • How to execute an SQL query present in a string inside an ABAP program?

    hello,
    How to execute an SQL query present in a string inside an ABAP program

    Raut,
    You can execute Native SQl statements.
    Ex: To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
    EXEC SQL [PERFORMING <form>].
      <Native SQL statement>
    ENDEXEC.
    There is no period after Native SQL statements. Furthermore, using inverted commas (") or an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a comment as it would in normal ABAP syntax. You need to know whether table and field names are case-sensitive in your chosen database.
    In Native SQL statements, the data is transported between the database table and the ABAP program using host variables. These are declared in the ABAP program, and preceded in the Native SQL statement by a colon (:). You can use elementary structures as host variables. Exceptionally, structures in an INTO clause are treated as though all of their fields were listed individually.
    If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.
    As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.
    EXEC SQL PERFORMING loop_output.
      SELECT connid, cityfrom, cityto
      INTO   :wa
      FROM   spfli
      WHERE  carrid = :c1
    ENDEXEC.
    Pls. Mark If useful

  • Build dynamic SQL query in Database Adapter.

    Hi All,
    I have a requirement to build dynamic sql query at Database Adapter.
    My BPEL process is getting search spec as input from siebel. I need to process this searchspec in BPEL and need to build the SQL query dynamically at Database Adapter to fetch the records from DB.
    it goes like this....
    1. Sieble Search Spec: city1 OR city2 OR city3 OR city4 .....
    I need to build query as
    select * from S_ADDR_PER where city like 'city1' OR city like 'city2' OR city like 'city3' OR city like 'city4' ......
    2. Siebel Search spec: city1 AND country1 AND state1....
    I need to build query as
    Select * from S_ADDR_PER where city like 'city1' AND country like 'country1' AND state like 'state1' ....
    3. Siebel Search spec: state
    I need to build query as
    select * from S_ADDR_PER where state like '%state%';
    Is it feasible in Database Adapter? if its Yes.
    Any guidelines to achieve this?
    Thank you
    Chandra

    Hi All,
    I have a requirement to build dynamic sql query at Database Adapter.
    My BPEL process is getting search spec as input from siebel. I need to process this searchspec in BPEL and need to build the SQL query dynamically at Database Adapter to fetch the records from DB.
    it goes like this....
    1. Sieble Search Spec: city1 OR city2 OR city3 OR city4 .....
    I need to build query as
    select * from S_ADDR_PER where city like 'city1' OR city like 'city2' OR city like 'city3' OR city like 'city4' ......
    2. Siebel Search spec: city1 AND country1 AND state1....
    I need to build query as
    Select * from S_ADDR_PER where city like 'city1' AND country like 'country1' AND state like 'state1' ....
    3. Siebel Search spec: state
    I need to build query as
    select * from S_ADDR_PER where state like '%state%';
    Is it feasible in Database Adapter? if its Yes.
    Any guidelines to achieve this?
    Thank you
    Chandra

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • How to build table join query in Jdeveloper

    Hi,
    Can someone tell me how to build table join query in Jdeveloper's Expression Builder UI?

    [Is it possible to create a table of contents in Crystal Reports?|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313335333133303330%7D.do]

  • Reg: sql query that prints all sundays in the year

    Hi all,
    Please give me sql query that prints all sundays in year. And when ever we execute that query then that will prints the sysdate(that is execution date).
    Thanks in Advance,
    -prasad.
    Edited by: prasad_orcl on Jun 5, 2009 9:13 PM

    Hi,
    Plz try this and let me know this works or not...
    SELECT DATE DATES,TO_CHAR(DATE,'DAY') DAYS FROM FISCAL_CALENDAR
    WHERE DATE_YEAR = 2009 AND
    DATE BETWEEN TRUNC(SYSDATE,'YEAR') AND
    ADD_MONTHS(TRUNC(SYSDATE,'YEAR'),12) -1 AND
    TRIM(TO_CHAR(DATE,'DAY')) = 'SUNDAY'
    ORDER BY DATE
    OUTPUT:
    DATES     DAYS
    1/4/2009     SUNDAY
    1/11/2009     SUNDAY
    1/18/2009     SUNDAY
    1/25/2009     SUNDAY
    2/1/2009     SUNDAY
    2/8/2009     SUNDAY
    2/15/2009     SUNDAY
    2/22/2009     SUNDAY
    3/1/2009     SUNDAY
    3/8/2009     SUNDAY
    3/15/2009     SUNDAY
    3/22/2009     SUNDAY
    3/29/2009     SUNDAY
    4/5/2009     SUNDAY
    4/12/2009     SUNDAY
    4/19/2009     SUNDAY
    4/26/2009     SUNDAY
    5/3/2009     SUNDAY
    5/10/2009     SUNDAY
    5/17/2009     SUNDAY
    5/24/2009     SUNDAY
    5/31/2009     SUNDAY
    6/7/2009     SUNDAY
    6/14/2009     SUNDAY
    6/21/2009     SUNDAY
    6/28/2009     SUNDAY
    7/5/2009     SUNDAY
    7/12/2009     SUNDAY
    7/19/2009     SUNDAY
    7/26/2009     SUNDAY
    8/2/2009     SUNDAY
    8/9/2009     SUNDAY
    8/16/2009     SUNDAY
    8/23/2009     SUNDAY
    8/30/2009     SUNDAY
    9/6/2009     SUNDAY
    9/13/2009     SUNDAY
    9/20/2009     SUNDAY
    9/27/2009     SUNDAY
    10/4/2009     SUNDAY
    10/11/2009SUNDAY
    10/18/2009SUNDAY
    10/25/2009SUNDAY
    11/1/2009     SUNDAY
    11/8/2009     SUNDAY
    11/15/2009SUNDAY
    11/22/2009SUNDAY
    11/29/2009SUNDAY
    12/6/2009     SUNDAY
    12/13/2009SUNDAY
    12/20/2009SUNDAY
    12/27/2009SUNDAY
    Regards
    Thiyag

  • How Can I find SQL Query in Database

    Dear Experts,
    How Can I find SQL Query in Database.

    Hi,
    U mena what query got executed in db? u can try V$SQL for it.
    Regards
    Bharath

  • What is sql query to print BOM hierarchy for a give item_number

    Hi,
    anyone is having sql query to print entire bom hiereachy for a given item number.
    Regards,
    ashok

    Try below query
    SELECT /* ORDERED FIRST_ROWS INDEX(MSI MTL_SYSTEM_ITEMS_U1)
    INDEX(BOM BOM_BILL_OF_MATERIALS_U2)
    INDEX(LU10 MFG_LOOKUPS_U1) INDEX(FCL FND_COMMON_LOOKUPS_U1) */
    rowidtochar(bet.rowid) row_id,
    bet.top_bill_sequence_id,
    bet.bill_sequence_id,
    bet.component_sequence_id,
    bet.component_item_id,
    bet.organization_id,
    bet.operation_seq_num,
    bet.plan_level,
    bet.extended_quantity,
    bet.item_num,
    bet.sort_order,
    bet.group_id,
    bet.item_cost,
    nvl(msi.reservable_type, 2) reservable_type,
    bet.extend_cost_flag,
    bet.top_alternate_designator,
    bet.top_item_id,
    bet.effectivity_date,
    bet.disable_date,
    bet.implementation_date,
    decode(bet.implementation_date, null, 2, 1) implemented_flag,
    bet.optional,
    bet.planning_factor,
    bet.component_yield_factor,
    bet.include_in_rollup_flag,
    bet.wip_supply_type wip_supply_type,
    ml2.meaning supply_type,
    bet.supply_subinventory,
    bet.supply_locator_id,
    bet.locator,
    bet.component_remarks,
    bet.change_notice,
    bet.component_quantity,
    bet.operation_lead_time_percent,
    bet.operation_offset,
    bet.mutually_exclusive_options,
    bet.check_atp,
    bet.required_to_ship,
    lu10.meaning so_basis,
    bet.required_for_revenue,
    bet.include_on_ship_docs,
    bet.low_quantity minimum_quantity,
    bet.high_quantity maximum_quantity,
    msi.primary_uom_code unit_of_measure,
    msi.item_type item_type,
    fcl.meaning item_type_description,
    msi.INVENTORY_ITEM_STATUS_CODE item_status,
    msi.description,
    msi.eng_item_flag,
    msi.cum_manufacturing_lead_time,
    msi.cumulative_total_lead_time,
    msi.full_lead_time manufacturing_lead_time,
    bom.assembly_item_id parent_item_id,
    bom.alternate_bom_designator parent_alternate,
    decode(bom.alternate_bom_designator, null, 2, 1) parent_alternate_flag,
    bom.assembly_type eng_bill,
    LPAD(bet.PLAN_LEVEL, LEAST(bet.PLAN_LEVEL, 8), '.') DISPLAY_PLAN_LEVEL,
    TO_CHAR(BET.EFFECTIVITY_DATE, 'HH24:MI') EFFECTIVITY_TIME,
    TO_CHAR(BET.DISABLE_DATE, 'HH24:MI') DISABLE_TIME,
    BET.EXTENDED_QUANTITY EXTENDED_QUANTITY6,          
    DECODE(BET.EXTEND_COST_FLAG, 1, BET.ITEM_COST * BET.EXTENDED_QUANTITY, 2, 0, NULL) EXTENDED_COST,
    BET.OPERATION_SEQ_NUM OPERATION_SEQ_NUM7,          
    MSI.BOM_ITEM_TYPE bom_item_type,
    MSI.REPLENISH_TO_ORDER_FLAG,
    MSI.PICK_COMPONENTS_FLAG,
    MSI.ATP_COMPONENTS_FLAG,
    MSI.ATP_FLAG,
    MSI.SHIPPABLE_ITEM_FLAG,
    MSI.MRP_PLANNING_CODE,
    MSI.SO_TRANSACTIONS_FLAG,
    MSI.CUSTOMER_ORDER_ENABLED_FLAG,
    MSI.INVOICE_ENABLED_FLAG,
    MSI.INVENTORY_ASSET_FLAG,
    MSI.SEGMENT1,
    MSI.SEGMENT1,
    BET.CURRENT_REVISION,
    MSI.GLOBAL_ATTRIBUTE6 ITEM_SPECIFICATION,
    BIC.ATTRIBUTE2 ITEM_SVC,
    BIC.ATTRIBUTE3 ITEM_SF,
    BIC.ATTRIBUTE10 ITEM_DPC,
    BIC.ATTRIBUTE12 RECV_DEPT_CD,
    BD.DEPARTMENT_CODE ROU_RECV_DEPARTMENT,
         msi.description ENG_DESC,
         msi.global_attribute6 ENG_SPEC,
         msi.primary_uom_code ENG_UOM,
         bet.component_quantity ENG_QTY,
         msi.item_type ENG_UIT,
         ml2.meaning ENG_SUPPLY_TYPE,
         bet.extend_cost_flag ENG_COST_FLAG,
    BIC.INCLUDE_IN_COST_ROLLUP INCLUDE_IN_COST_ROLLUP,
    msi.planning_make_buy_code,
    bet.Attribute13,
    bet.Attribute14,
    MSI.GLOBAL_ATTRIBUTE9,
    msi.segment9 AI_TYPE
    FROM MFG_LOOKUPS ML2,
    MFG_LOOKUPS LU10,
    FND_COMMON_LOOKUPS FCL,
    BOM_BILL_OF_MATERIALS BOM,
    MTL_SYSTEM_ITEMS MSI,
    BOM_SMALL_EXPL_TEMP BET,
    BOM_INVENTORY_COMPONENTS BIC,     
    BOM_OPERATIONAL_ROUTINGS BOR,
    BOM_OPERATION_SEQUENCES BOS,
    BOM_DEPARTMENTS BD               
    WHERE bet.component_item_id = msi.inventory_item_id
    and bet.bill_sequence_id = bom.bill_sequence_id
    and bet.organization_id = msi.organization_id
    and lu10.lookup_code (+) = bet.so_basis
    and bic.component_sequence_id(+) = bet.component_sequence_id     
    and lu10.lookup_type (+) = 'BOM_SO_BASIS'
    and fcl.lookup_code (+) = msi.item_type
    and fcl.lookup_type (+) = 'ITEM_TYPE'
    and fcl.application_id (+) = 401
    and ml2.lookup_code (+) = bet.wip_supply_type
    and ml2.lookup_type (+) = 'WIP_SUPPLY'
    and bet.assembly_item_id = bor.assembly_item_id(+)     
    and bet.organization_id = bor.organization_id(+)
    and bor.alternate_routing_designator(+) is null
    and bor.routing_sequence_id = bos.routing_sequence_id(+)
    and 10 = bos.operation_seq_num(+)               
    and bos.effectivity_date(+) <= sysdate
    and sysdate < nvl(bos.disable_date(+),sysdate + 1)
    and bos.department_id = bd.department_id(+)          
    /

  • How to get an sql query result to a textbox?

    i am working with jdk1.4 and office 2003.
    i need to run the following SQL Query: "SELECT max(BookId) as BookId FROM Books" where BookId is an autonumeric generated number obtained from the field autonumber in access 2003 database.
    now, the result of this must be placed in a textbox.
    does anyone knows how to do this?
    I ve tried this but nothing happens and niether any error comes
    st = con.createStatement ();     //Creating Statement Object.
    long bookNo;          //Use for Comparing the Book's Id.
    try {     //SELECT Query to Retrieved the Record.
    String q = "SELECT max(BookId) as BookId FROM Books";
    ResultSet rs = st.executeQuery (q);     //Executing the Query.
    bookNo = rs.getLong ("BookId");          //Storing the Record.
    bookNo =(bookNo+1);
    txtBookId.setText (""+bookNo);
    catch (SQLException sqlex) { }
    does anyone knows how to do this?????plz help me out.
    Thanks
    Aanchal

    Hi Aanchal,
    If an SQL error occurs now, you cannot see it in your code. You should do something with the exception you catch, e.g. printing it: sqlex.printStackTrace(), so that you can see if something goes wrong.
    For your number, you should move the cursor in the resultset to the first row - either by: calling first( ) or next ( ), then you can retrieve your booknumber.
    Best Regards,
    Martijn

  • SQL Query to print 1-n numbers?

    for(int i =0; i<n i++)
    We can print 1-n numbers on the console by using above loop.
    In the sameway How I can display 1-n numbers on SQL console by using SQL Query..?
    Can any body help me regarding this?>

    SowmyRaj wrote:
    hi justin.... thanks for ur answer.... can u give me ur yahoo or gmail id?Now, i'm really stunned by your so many rapid posted threads and that too you can do yourself if you invested some time and make some R&D work.
    I don't want to hurt your feeling but i think you should invest some time to do this job. Or, you can get plenty of related solution and then you have to customize those to your required solution. Only that will help you to earn knowledge.
    You know one general suggestion -> Try to do the solution by yourself. If you stuck or don't have any clue then post it here - we will post the clue or post your required solution if you stuck.
    We are always there to help you. Don't mind.
    Regards.
    Satyaki De.

Maybe you are looking for