Modification to Query

Hi Guys,
Gordon very kindly posted this query for another user, I am wondering if it is possible to alter it to reflect my Companies financial Year, which starts on the 1st August and ends 30th July, is this possible at all, had a try myself but got hopelessly lost. I was also trying to add in Gross Profit and Gross Profit % in as well but that really made it worse, I will be using this in a Crystal Report and also kept getting a /by Zero error message when I added the Gross Profit % field.
SELECT P.CardCode, P.CardName,
[1] as [Jan],
[2] as [Feb],
[3] as [Mar],
[4] as [Apr],
[5] as [May],
[6] as [Jun],
[7] as [Jul],
[8] as [Aug],
[9] as [Sep],
[10] as [Oct],
[11] as [Nov],
[12] as [Dec]
FROM
(SELECT T0.CardCode, T0.CardName, (T1.Debit - T1.Credit) as [Amount], MONTH(T1.duedate) as [month]
FROM dbo.OCRD T0
JOIN dbo.JDT1 T1 On T1.ShortName = T0.CardCode
WHERE Year(T1.duedate)=Year(GetDate()) AND T1.TransType
in ('13','14')) S
  PIVOT  (SUM([Amount]) FOR [month] IN
([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
Any help would be greatly appreciated. Also the reason I am not using the Sales Analysis report is due to the fact the the directors also want a series of dashboards in the Crystal Report.
Kind regards
Sean

Hi,
Try this..........
Just give your financial year start and end date in from date & To date................
SELECT P.CardCode, P.CardName,
[1] as Jan,
[2] as Feb,
[3] as Mar,
[4] as Apr,
[5] as May,
[6] as Jun,
[7] as Jul,
[8] as Aug,
[9] as Sep,
[10] as Oct,
[11] as Nov,
[12] as Dec
FROM
(SELECT T0.CardCode, T0.CardName, (T1.Debit - T1.Credit) as Amount, MONTH(T1.duedate) as month
FROM dbo.OCRD T0
JOIN dbo.JDT1 T1 On T1.ShortName = T0.CardCode
WHERE T1.RefDate>='[%0]' and T1.RefDate<='[%1]'  AND T1.TransType
in ('13','14')) S
PIVOT (SUM(Amount) FOR month IN
([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
Regards,
Priya

Similar Messages

  • Modification of Query in ABAP HR

    Hi folks,
             I need to check data in the infotype 2002 with some conditions. I have written the query like this.
    *select single * from pa2002 where pernr = it_ptrv-pernr*
                                      and   begda = it_ptrv-pdatv
                                      and   endda = it_ptrv-pdatb
                                      and   subty = '0930'.
          if sy-subrc ne 0.
    Its working fine, but because of some authorization problem, i need to change the query. instead of using Select statement i need to use statement RP_READ_INFOTYPE. As i am new to ABAP HR i dont know its usage. Could any body tell me how to write same above query using rp_read statement with same conditions. pls help me..
                Thanks in advance,
                Ram.

    Use FM : 'HR_READ_INFOTYPE'
    data : it_infty type table of pa2002 with  header line,
    CALL FUNCTION 'HR_READ_INFOTYPE'
      EXPORTING
        pernr                 = p_pernr
        infty                 = '2002'
       BEGDA                 = it_ptrv-pdatv
       ENDDA                 = it_ptrv-pdatb
      BYPASS_BUFFER         = ' '
      LEGACY_MODE           = ' '
    IMPORTING
      SUBRC                 =
      tables
        infty_tab             = it_infty
    EXCEPTIONS
      INFTY_NOT_FOUND       = 1
      OTHERS                = 2
    read table it_infty with key pernr = p_pernr
                                           subty = '0930'.
    if sy-subrc <> 0.
    endif.

  • Modification of Query for report

    Dear All,
    In inventory one standard report -- Material account distribution summary and RDF is INVTRACS.rdf. this report will give whole transaction activity amount between two days. but our clients needs details of quantity and cost for every transaction then i will sum all those amounts. for this one i was developed one query. If u ran standard report it will gives net activity amount like--12164931.9 and ran my query it gives total amount -- 12163701.9 .It's having diff . but this query is working for some branches i.e for some branches standard report net activity amount and i developed query is same, but for some branches it's comes diff. same query but it is works for some branches only. and report name is 'INVTRACS.rdf'. my requirement for all branches it should be equal to standard report output amount and my query out. pls any body help me .it's urgent.
    i was developed this query..
    select mtt.organization_id,
         mtts.transaction_type_name,
    --     mtts.TRANSACTION_SOURCE_NAME,
         msi.segment1 item_code,
         mtt.transaction_quantity,
         mtt.SHIPMENT_NUMBER,
         mtt.TRANSACTION_UOM,
         mtt.TRANSACTION_DATE,
         imt.TRANSACTION_SRC_HDR,
         houv.NAME     ,
         cid.UNIT_COST ,
         round(mtt.transaction_quantity*to_number(cid.UNIT_COST),4) total
    from mtl_material_transactions mtt,
         mtl_system_items msi,
         mtl_transaction_types mtts,
         INVFV_MATERIAL_TRANSACTIONS imt,
         hr_organization_units houv ,
         CST_INV_DISTRIBUTION_V cid
    where
    to_date(to_char(mtt.transaction_date,'dd-mon-yy')) between '01-jul-08' and '31-jul-08'
    --and mtt.organization_id = 115
    and msi.inventory_item_id = mtt.inventory_item_id
    and msi.organization_id = 105
    and cid.TRANSACTION_ID=mtt.TRANSACTION_ID
    and mtts.transaction_type_id = mtt.transaction_type_id
    and mtt.TRANSACTION_ID=imt.TRANSACTION_ID
    and cid.ACCOUNTING_LINE_TYPE='1'
    --and mtt.transaction_id = '588156'
    and mtt.ORGANIZATION_ID=houv.ORGANIZATION_ID
    and houv.NAME     = :p_name

    any body

  • Error while executing query

    Hi all,
    I am not able to execute a report in BEx Analyzer. It keeps asking for userid and password and after that it gives message saying Query not yet calculated. When tried to execute again using the refresh button it disconnects from BW server. (I am typing correct userid and password).
    Tried to check for the query that was created. Even the query doesnt open in BEx Query Designer. It gives error message saying - System Error in Program CL_RSD_MULTIPROV and from FACTORY -02.
    Program error in class SAPMSSY1 method: UNCAUGHT_EXCEPTION
    (This query is built on Multiprovider). I went in the BW system and checked if the Multiprovider and its cubes were inactive. I found that there was no problem with Multiprovider and its cubes. All are in active and executable state.
    not sure what the problem is. Do let me know how we can resolve this issue.
    Thanks in advance.
    Maddy

    Hi,
    Reason for such error could be that you had some info-object either characteristic or key-figure in your query which now is deleted and since you are trying to open that query it is checking that info-object in source (multi-provider/cube/dso/infoset whatever is applicable in your case) which is not available and hence giving this error.
    You need to add that info-object in info-provider on which  query is built, ones you add that do necessary modification in query and then remove unwanted info-object from multi-provider.
    Regards,
    Akshay

  • About Query

    What are the steps involved in creation of query using SQVI.
    Whic option is to be selected  i.e Table or Table Join .
    Also what is the significance of Basis mode and Layout Mode .
    Also for already existed queries in system how to find which is the user who have created the query and whether queries are user specific. Means if i wanted to do some modifications in query whether it has to be done thru the same user who have created the query.
    Please guide.

    Please check this answered link:
    SAP Query

  • Bug in BC4J test query while creating view based on query

    In BC4J while creating a view from query if we test our query , BC4J modify the query with the following one :
    "SELECT * FROM ( " + ourQuery + " ) where 1=2;"
    so for the Query like "SELECT ename,ename from emp" which is a valid query it modifies it to
    "SELECT * FROM ( SELECT ename,ename from emp ) where 1=2;"
    which is an invalid Query and BC4J get a SQLException:column ambiguously defined and Test fails
    BC4J does this modification in query because it doesn't want to Fetch Data from Database and add the where clause
    to the query but in Cases like above this modification doesn't work properly.
    one way to solve the problem is by giving alias name to the columns of query.Is there any other way to do the same as my query is completely Valid and i don't want to change it at all ?

    Hi Jan,
    Actually I am getting my query at run time and based on that I am creating a view.This Query can be given by User of my application and at that time it'll be very painful for me to handle that.
    It's definately a Bug in BC4J as they should not modify the query in this way.Thanx for ur interest in my problem.

  • Query created in BW dev, modified in BW Q and want to transport from Q to P

    Hello all,
    I have created query in BW dev and then transported to BW qa, we had to modifed the query in BWqa system. There are a lot of queries we have done like this.
    Now I want to transport only the queries (BEX objects) from Qa to Prod staright away, can that we done. If yes, do we have to create new package for transporting the bex objects.
    Also how do we change the assigned packages on the elements which are not modified/created in QA since they already have package assigned to them wheich was created in BW dev.?
    Thanks in advance,
    Raj

    What K J is trying to say is that the usual and recommendable transport path is
    Dev to Quality -- Test the changes throughly
    if satisfactory
    DEV to Prod (the same transport needs to be imported into Prod)
    else
    go back to Dev and make the required changes and go back to the above step of testing in Q until sucessful.
    By moving the same transport across the systems, you can ensure that all the systems are in sync. Lets say you started a query in Dev, moved it into Q and realized that you didnt add a field. Instead of coming back to Dev to do this, if you start making changes in Q (many clients do not allow this, but I've heard of some which do), collect the transport and move it into Prod...then the Q and Dev systems are out of sync! The query in Dev and that in Q are not the same.
        Assign pts if helpful.

  • Unable to get into query designer in Dev

    Hi BW Gurus,
    I am trying to get into query designer to do modifications to query in Dev server. But it is not allowing me to enter. It is displaying the following messages.
    BEx Transport request is not available or not suitable
    Choose another request
    with the above messages I am trying to enter query designer. But it is in display mode only but not in editable mode. So kindly guide me how to solve this. I have to change the query.

    it means there is no transport request availabke to chenge your query.
    RSA1>transport connection>click 'create transport requets for Bex' (truck icon with BEX)>select your package->change>assign a request if you have already(or create new one)->continue.
    log off and log into Bex.you will be able to change your query now.

  • Sorting at Form Level

    Dear All,
    thanx for my earliar queries, tahnx a lot.
    i am working on Forms 6i / Oracle 8i.Actaully, i need to sort some records on form level, which i got populated in the form one-by-one by the primary key.
    pls, suggest me how to proceed.
    Inderjeet Singh

    It's not Forms that does the sorting, but the database. That's why you modify the ORDER BY clause of the block; Forms passes it to the database which modifies the query accordingly.
    So one option is to base your block on a view, which can include your derived field. This is useful for sorting on things like foreign key lookups.
    If the thing you want to sort is not in the database, then you can implement your sort using PL/SQL and manipulating the blocks using the block and record built-ins.
    Regards,
    Robin Zimmermann
    Forms Product Management

  • Join, and filter...

    When doing a join, and filtering, I want the filter to be applied first. For example
    if the callDisp file for the given date has 18 rows, and the treeProject has 47 records
    SELECT COUNT(*) from treeProject, callDisp
    Where
    treeProject.projectcode = callDisp.projectcode(+) and
    treeProject.childcode = callDisp.disp(+) and
    treeProject.projectcode = 'project' and
    calldisp.dispDateTime >= to_date( '01-14-2003', 'MM-DD-YYYY' );
    COUNT(*)
    17
    The idea is to list all of the rows meeting the critera in the treeproject, by doing the outer join on the callDisp table. Which works fine if the datetime part of the query is not entered. I tried modifing the query to add the nulls:
    SELECT COUNT(*) from treeProject, callDisp
    Where
    treeProject.projectcode = callDisp.projectcode(+) and
    treeProject.childcode = callDisp.disp(+) and
    treeProject.projectcode = 'project' and
    calldisp.dispDateTime >= to_date( '01-14-2003', 'MM-DD-YYYY' ) or
    calldisp.dispDateTime is null
    COUNT(*)
    18
    or even:
    SELECT COUNT(*) from treeProject, callDisp
    Where
    treeProject.projectcode = callDisp.projectcode(+) and
    treeProject.childcode = callDisp.disp(+Long postings are being truncated to ~1 kB at this time.

    or even:
    SELECT COUNT(*) from treeProject, callDisp
    Where
    treeProject.projectcode = callDisp.projectcode(+) and
    treeProject.childcode = callDisp.disp(+) and
    treeProject.projectcode = 'project' and
    calldisp.dispDateTime >= to_date( '01-14-2003', 'MM-DD-YYYY' ) or
    nvl(calldisp.dispDateTime,to_date( '01-14-2003', 'MM-DD-YYYY' ) ) = to_date( '01-14-2003', 'MM-DD-YYYY' )
    COUNT(*)
    18
    But without getting the desired results. I want the filter to occur first, and the join to occur last.
    Thanks
    Rich

  • Filtering on Multiple wildcards

    Hi. I'm using SSRS 2008 and I've created a report of some computers and I added a parameter to filter by computer name using a wildcard. Eg Computer* 
    This is filtered using the Filter on the dataset so the Expression = Computer_Name 
    Operator Like
    Value <parameter for the report>
    However my boss now decides that he wants to be able to filter by multiple computer names. Like
    Computer*,Server*
    Any ideas how I'd go about this I'm completely stuck. 

    Hi ChirsC200,
    According to your description, you want to have a multi value parameter to filter records which the field is like the values in parameter. Right?
    In this scenario, we can’t use filters to achieve this goal because it only has AND logic between filters, but we need OR logic. And simply modification in query is not working as well. However, we can create a function to split the string in parameter and
    put divided string into a table, then we compare the field with the records in the table and filter the records which are like the wildcards. We have tested this case in our local environment. Here are steps and screenshots for your reference:
    1. Create a function in database. Execute the commands below:
    CREATE FUNCTION [dbo].[SplitParameterValues] (@InputString NVARCHAR(max), @SplitChar VARCHAR(5))
    RETURNS @ValuesList TABLE
    param NVARCHAR(255)
    AS
    BEGIN
    DECLARE @ListValue NVARCHAR(max)
    SET @InputString = @InputString + @SplitChar
    WHILE @InputString!= @SplitChar
    BEGIN
    SELECT @ListValue = SUBSTRING(@InputString , 1, (CHARINDEX(@SplitChar, @InputString)-1))
    IF (CHARINDEX(@SplitChar, @InputString) + len(@SplitChar))>(LEN(@InputString))
    BEGIN
    SET @InputString=@SplitChar
    END
    ELSE
    BEGIN
    SELECT @InputString = SUBSTRING(@InputString, (CHARINDEX(@SplitChar, @InputString) + len(@SplitChar)) , LEN(@InputString)-(CHARINDEX(@SplitChar, @InputString)+ len(@SplitChar)-1) )
    END
    INSERT INTO @ValuesList VALUES( @ListValue)
    END
    RETURN
    END
    2. Create a procedure to get records which are like the wildcards in parameter.
    Create PROCEDURE sp (@Type nvarchar(50))
    AS
    SELECT     DocID,Type
    FROM         Computer c
    inner join (SELECT [param] FROM SplitParameter
    Values (@Type,',')) s on c.Type like (s.[param]+'%')  
    Ps: You may need to modify in query part based on your table structure.
    3. Go to report. Create a parameter, set specific value (Computer, Server….) in Available Values.
    4. Create a dataset and get data for the Procedure sp.
    5. Save and preview. It looks like below:
    Reference:
    [Forum FAQ]How do I add a search feature
    in the parameter with long drop down list?
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou (Pactera)

  • Populating a combo box using values in a table

    I am trying to populate a drop down box with values from a table. I have got so far.
    The combo box is populated however the values in the box are blank.
    Can some suggest the necessary modifications?
    $query="select distinct(house_type) from tbl_accommodation";
    $stmt = ociparse($conn, $query);
    ociexecute($stmt);
    echo '<select name="house_type">';
    echo '<option value = "-1">Select:</option>';
    while($row=ocifetch($stmt)) {
         echo '<option>' . $row['house_type'] . '</option>';
         echo '</select>';
    Thanks

    The ocifetch() function needs ociresult() to get the data. See
    http://us.php.net/manual/en/function.oci-result.php
    You might want to use oci_fetch_assoc() instead.
    while($row=oci_fetch_assoc($stmt)) {
      echo '<option>' . $row['HOUSE_TYPE'] . '</option>';
    }For associative arrays, use the column name in upper case.
    NB Oci_fetch_assoc() is a PHP 5 function. If you don't have it, then
    you are using PHP 4 which has a much older version of the OCI8
    extension. I'd recommend upgrading PHP, or just replacing the old
    OCI8 with a newer one. See other recent threads about how to do this.

  • Project was not deleted error

    Hi,
    We are using MII 12.0 version. I imported one project into it and after some modifications in query templates, when i tried to delete it from System Management -> Projects page , it is showing alert as "Project was not deleted".
    I am able to delete other projects. I tried to delete from work bench there it is showing error as "Error On Delete: org.xml.sax.SAXParseException: Content is not allowed in prolog".
    What is the problem and how to delete that project.
    Regards,
    Senthil
    Edited by: senthil kumar on Nov 16, 2010 1:00 PM

    Hi,
    We found the problem and deleted the project.
    We tried it by deleting folder by folder. While deleting In one folder it showed same prolog error and it is coming when one particular transaction is being deleted. When we analysed, we found that this transaction is not loaded successfully as it contains error data as letters like @#$@$@*$@&&!#$ as continously. we replaced this transaction with new empty transaction with same name and we tried again to delete and it is deleted. after that we were able to delete the project from Project page.
    Thanks.
    Regards,
    Senthil

  • Problem filtering using between dates

    Hi, I have a Measure in Webi that has to show the Invoicing Quantity between 2 dates. The thing is that i don't know how to do it and I tried many many times. The Dimension that has the date is a date field.
    The thing is that i tried to "check" if i'm mispelling something and I added the dates (start date and End DAte) as filters in the execution of the consult and it brings the data without any fail and also the correct quantities.
    How can I filter the invoicing quantities between 2 dates using a Measure?
    Thanks in advance,
    Reynaldo

    Hi Stratos, I have created a derived table in order to bring the Invoicing. The Dates aren't prompts fields, there are a Formula that if a launch the report today, it has to bring the invoices between monday and friday of last week, and also the sales of the last 21 days (that's the second column).
    The database is Oracle, I think the trouble is how the dates are shown by the DB, because are formated in DD/MM/YYYY HH:MM:SS and I need it only DD/MM/YYYY. I used the function To_date by oracle, but, still brings the HH:MM:SS, when I look for the values of the table.
    This problem, I think is going also to Webi and when I try to filter using a Measure doesn't bring data, but If I use the filter used by Webi (the one that modifies the query, brings the data ok)
    Can you help me?.
    Thanks in advance,
    PD: Hope you understand!
    Reynaldo

  • Compilation error in procedure

    P_start_date and p_end_date is input to the procedure
    it is giving execution error.
    v_sql := 'SELECT
         as_no ,
         l_no ,
         dtc_no ,
         reg_date ,
         card_no ,
         last_name ,
         no_mail ,
         no_call      
    FROM registration@' ||p_db_link || ' a
    WHERE a.first_name IS NOT NULL
    AND a.datestamp = (SELECT max(b.datestamp) FROM registration@' ||p_db_link || ' b
    WHERE a.card_no = b.card_no)
    AND TO_DATE(a.reg_date,''dd-mon-yy'') BETWEEN ' || p_start_date || ' AND ' || p_end_date ;
    ========= Here is the sql while executing...
    SELECT
    as_no ,
    l_no ,
    dtc_no
    reg_date ,
    card_no ,
    last_name
    first_name ,
    zip_code ,
    start_weight
    goal_weight ,
    mbrship_status ,
    weeks_completed ,
    height
    previous_wt ,
    previous_date ,
    datestamp ,
    notes
    modified_date ,
    old_style_reg_no ,
    lifetime_no
    miss_you_sent ,
    miss_you_datestamp ,
    address ,
    city
    state ,
    phone ,
    phone_type ,
    email
    memo ,
    sex ,
    birth_date
    age_range ,
    no_mail ,
    no_call
    FROM
    registration@link_champ a
    WHERE a.first_name IS NOT NULL
    AND a.datestamp =
    (SELECT max(b.datestamp) FROM registration@link_champ b
    WHERE a.card_no = b.card_no)
    AND TO_DATE(a.reg_date,'dd-mon-yy') BETWEEN
    10-MAR-06 AND 11-MAR-06
    ErrorORA-00904: "MAR": invalid identifier
    ORA-Error in fetching the cursor values
    PL/SQL procedure successfully completed.

    they are date type
    I modifed the query and it is working fine now, but it is still taking lots of time...
    Here is what i changed the procedure....
    I have used the bulk collect here, but still there is no big performance improvement..
    CREATE OR REPLACE PACKAGE BODY pkg_merge_member_info IS
    PROCEDURE p_merge_member_info(p_db_link in VARCHAR2, p_start_date in date, p_end_date in date) IS
    generic_cv sys_refcursor;
    generic_cv2 sys_refcursor;
    generic_cv3 sys_refcursor;
    v_rcw_card_no varchar2(20);
    v_pmi_inactive_date date;
    v_pmi_inactive_reason varchar2(50);
    v_ccw_last_meeting date;
    type     tbl_as_no           is table of      NUMBER(8)     INDEX BY BINARY_INTEGER;
    type     tbl_l_no           is table of      NUMBER(8)     INDEX BY BINARY_INTEGER;
    type     tbl_dtc_no           is table of      NUMBER(8)     INDEX BY BINARY_INTEGER;
    type     tbl_reg_date           is table of      DATE     INDEX BY BINARY_INTEGER;
    type     tbl_card_no           is table of      VARCHAR2(20)     INDEX BY BINARY_INTEGER;
    type     tbl_last_name           is table of      VARCHAR2(32)     INDEX BY BINARY_INTEGER;
    type     tbl_first_name           is table of      VARCHAR2(32)     INDEX BY BINARY_INTEGER;
    type     tbl_zip_code           is table of      CHAR(5)     INDEX BY BINARY_INTEGER;
    type     tbl_start_weight           is table of      NUMBER(8,2)     INDEX BY BINARY_INTEGER;
    type     tbl_goal_weight           is table of      NUMBER(8,2)     INDEX BY BINARY_INTEGER;
    type     tbl_mbrship_status           is table of      VARCHAR2(32)     INDEX BY BINARY_INTEGER;
    type     tbl_weeks_completed           is table of      NUMBER(8)     INDEX BY BINARY_INTEGER;
    type     tbl_height           is table of      NUMBER(8,2)     INDEX BY BINARY_INTEGER;
    type     tbl_previous_wt           is table of      NUMBER(8,2)     INDEX BY BINARY_INTEGER;
    type     tbl_previous_date           is table of      DATE     INDEX BY BINARY_INTEGER;
    type     tbl_datestamp           is table of      DATE     INDEX BY BINARY_INTEGER;
    type     tbl_notes           is table of      VARCHAR2(128)     INDEX BY BINARY_INTEGER;
    type     tbl_modified_date           is table of      DATE     INDEX BY BINARY_INTEGER;
    type     tbl_old_style_reg_no           is table of      VARCHAR2(32)     INDEX BY BINARY_INTEGER;
    type     tbl_lifetime_no           is table of      VARCHAR2(32)     INDEX BY BINARY_INTEGER;
    type     tbl_miss_you_sent           is table of      CHAR(1)     INDEX BY BINARY_INTEGER;
    type     tbl_miss_you_datestamp           is table of      DATE     INDEX BY BINARY_INTEGER;
    type     tbl_address           is table of      VARCHAR2(64)     INDEX BY BINARY_INTEGER;
    type     tbl_city           is table of      VARCHAR2(32)     INDEX BY BINARY_INTEGER;
    type     tbl_state           is table of      CHAR(2)     INDEX BY BINARY_INTEGER;
    type     tbl_phone           is table of      VARCHAR2(16)     INDEX BY BINARY_INTEGER;
    type     tbl_phone_type           is table of      VARCHAR2(4)     INDEX BY BINARY_INTEGER;
    type     tbl_email           is table of      VARCHAR2(64)     INDEX BY BINARY_INTEGER;
    type     tbl_memo           is table of      VARCHAR2(192)     INDEX BY BINARY_INTEGER;
    type     tbl_sex           is table of      CHAR(1)     INDEX BY BINARY_INTEGER;
    type     tbl_birth_date           is table of      DATE     INDEX BY BINARY_INTEGER;
    type     tbl_age_range           is table of      VARCHAR2(8)     INDEX BY BINARY_INTEGER;
    type     tbl_no_mail           is table of      CHAR(1)     INDEX BY BINARY_INTEGER;
    type     tbl_no_call           is table of      CHAR(1)      INDEX BY BINARY_INTEGER;
    v_AS_NO tbl_as_no      ;
    v_L_NO tbl_l_no      ;
    v_DTC_NO tbl_dtc_no      ;
    v_REG_DATE tbl_reg_date      ;
    v_CARD_NO tbl_card_no      ;
    v_LAST_NAME tbl_last_name      ;
    v_FIRST_NAME tbl_first_name      ;
    v_ZIP_CODE tbl_zip_code ;      
    v_START_WEIGHT tbl_start_weight ;      
    v_GOAL_WEIGHT tbl_goal_weight ;     
    v_MBRSHIP_STATUS tbl_mbrship_status ;     
    v_WEEKS_COMPLETED tbl_weeks_completed ;     
    v_HEIGHT tbl_height ;     
    v_PREVIOUS_WT tbl_previous_wt ;     
    v_PREVIOUS_DATE tbl_previous_date ;     
    v_DATESTAMP tbl_datestamp ;     
    v_NOTES tbl_notes ;     
    v_MODIFIED_DATE tbl_modified_date ;     
    v_OLD_STYLE_REG_NO tbl_old_style_reg_no ;     
    v_LIFETIME_NO tbl_lifetime_no ;     
    v_MISS_YOU_SENT tbl_miss_you_sent ;     
    v_MISS_YOU_DATESTAMP tbl_miss_you_datestamp ;     
    v_ADDRESS tbl_address ;     
    v_CITY tbl_city ;     
    v_STATE tbl_state ;     
    v_PHONE tbl_phone ;     
    v_PHONE_TYPE tbl_phone_type ;     
    v_EMAIL tbl_email ;     
    v_MEMO tbl_memo ;     
    v_SEX tbl_sex ;     
    v_BIRTH_DATE tbl_birth_date ;     
    v_AGE_RANGE tbl_age_range ;     
    v_NO_MAIL tbl_no_mail ;     
    v_NO_CALL tbl_no_call ;     
    o_error_Text VARCHAR2(1000);
    v_sql_err VARCHAR2(4000);
    tname VARCHAR2(32);
    o_status VARCHAR2(10);
    --v_schema_name                              VARCHAR2(100):=p_schema_name||'.';
    v_last_upd_by VARCHAR2(20) :='Apollo Data Refresh';
    v_created_by VARCHAR2(20) :='Apollo Data Refresh';
    v_user_check_id NUMBER(10);
    v_hire_date DATE;
    v_fjc_no VARCHAR2(1);
    v_sql VARCHAR2(4000);
    v_emp_check NUMBER(1) := 0;
    v_user_id NUMBER(10);
    v_state_id NUMBER(10);
    v_ejc_date_last_worked      DATE;
    v_member_id NUMBER(10);
    v_MEMBER_TYPE_ID NUMBER(10);
    BEGIN
    v_sql := 'SELECT
         as_no ,
         l_no ,
         dtc_no ,
         reg_date ,
         card_no ,
         last_name ,
         first_name ,
         zip_code ,
         start_weight ,
         goal_weight ,
         mbrship_status ,
         weeks_completed ,
         height ,
         previous_wt ,
         previous_date ,
         datestamp ,
         notes ,
         modified_date ,
         old_style_reg_no ,
         lifetime_no ,
         miss_you_sent ,
         miss_you_datestamp ,
         address ,
         city ,
         state ,
         phone ,
         phone_type ,
         email ,
         memo ,
         sex ,
         birth_date ,
         age_range ,
         no_mail ,
         no_call      
    FROM registration@' ||p_db_link || ' a
    WHERE a.first_name IS NOT NULL
    AND a.datestamp = (SELECT max(b.datestamp) FROM registration@' ||p_db_link || ' b
    WHERE a.card_no = b.card_no)
    AND TO_DATE(a.reg_date,''dd-mon-yy'') BETWEEN ''' || p_start_date || ''' and ''' || p_end_date ||'''' ;
    --AND  TO_DATE(a.reg_date,''dd-mon-yy'') BETWEEN   p_start_date and p_end_date  ' ;
    --USING  p_start_date, p_end_date    ;
    o_Error_Text := 'ORA-Error in fetching the cursor values ';
    tname:= NULL;
    dbms_output.put_line(v_sql);
    execute immediate v_sql bulk collect into
         v_as_no ,
         v_l_no ,
         v_dtc_no ,
         v_reg_date ,
         v_card_no ,
         v_last_name ,      
         v_first_name ,
         v_zip_code ,
         v_start_weight ,
         v_goal_weight ,
         v_mbrship_status ,
         v_weeks_completed ,
         v_height ,
         v_previous_wt ,
         v_previous_date ,
         v_datestamp ,
         v_notes ,
         v_modified_date ,
         v_old_style_reg_no ,
         v_lifetime_no ,
         v_miss_you_sent ,
         v_miss_you_datestamp ,
         v_address ,
         v_city ,
         v_state ,
         v_phone ,
         v_phone_type ,
         v_email ,
         v_memo ,
         v_sex ,
         v_birth_date ,
         v_age_range ,
         v_no_mail ,
         v_no_call ;
    FOR i IN v_card_no.FIRST..v_card_no.LAST
    LOOP
    o_Error_Text := 'ORA-Error in getting member id for the card no';
    tname:= 'members';
         SELECT count(1) INTO v_emp_check
         FROM members
         WHERE champ_code=v_CARD_NO(i);
    IF v_emp_check = 0 THEN
    o_Error_Text := 'ORA-Error in executing sequence seq_user_id';
    tname:= NULL;
    SELECT user_id_seq.nextval INTO v_user_id FROM dual;
    o_Error_Text := 'ORA-Error in INSERTing to users table';
    tname:= 'Users';
         INSERT INTO users
         ( user_id ,
              user_type_id ,
              first_name ,
              last_name ,
              mid_name ,
              gender ,
              date_of_birth ,
              notes ,
              site_id ,
              created_date ,
              created_by ,
              last_upd_date ,
              last_upd_by
         VALUES
         ( v_user_id ,
              2 , -- Member type
              v_first_name(i),
              v_last_name(i) ,
              null , -- mid name
              v_sex(i) , -- gender
              v_birth_date(i) ,
              v_notes(i) ,
              1 , -- site id
              pkg_utilities.fn_sysdate(1) , -- Created Dt
              v_created_by , -- Created by
              pkg_utilities.fn_sysdate(1) , -- Modified Dt
              v_last_upd_by -- Modified by
    end if;
    dbms_output.put_line(i);
    end loop;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Error' ||sqlerrm);
    DBMS_OUTPUT.PUT_LINE(o_error_text);
    v_sql_err :=SQLERRM;
    ROLLBACK;
    pkg_champ_message_log.champ_message_log ('pkg_merge_employee_info.p_merge_employee_info', tname, null,'Apollo', v_sql_err,'Error',o_Error_Text,O_STATUS);
    end;
    END PKG_MERGE_member_INFO;
    /

Maybe you are looking for