How to join 2 separate SQL Statements into 1 command

Hi Everyone,
I'm pretty new to PL/SQL.. thanks for your help. I'm hoping the answer to this is pretty straight forward.
I have a report (crystal) that has 1 subreport. The results from the report are exported to excel. I'd like to take this report and include it in another report, however since I've already went 1 sub report down, looks like I need to figure out a way to get this 1 report combined into a SQL Command.
Is there an easy way to combine the main report and subreport here into 1 SQL Command?
Main Report SQL Select
SELECT DISTINCT "ST_WORKORDER_REF"."st_wo_number", "ST_WORKORDER_REF"."gs_guid", "ST_STATION"."st_workorder_ref_guid", "ST_STATION"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid", "GS_ASSEMBLY_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid", "GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_quantity", "GS_ASSEMBLY_REF"."gs_assembly_description", "GS_ASSEMBLY_REF"."gs_display_feature_name", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_name", "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_date_created", "ST_ATTACHED_ASSEMBLIES"."gs_display_feature_name"
FROM   ((("gs54025_master"."dbo"."ST_WORKORDER_REF" "ST_WORKORDER_REF" LEFT OUTER JOIN "gsXXXXX"."dbo"."ST_STATION" "ST_STATION" ON "ST_WORKORDER_REF"."gs_guid"="ST_STATION"."st_workorder_ref_guid") LEFT OUTER JOIN "gs54gsXXXXX"."dbo"."ST_ATTACHED_ASSEMBLIES" "ST_ATTACHED_ASSEMBLIES" ON "ST_STATION"."gs_guid"="ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_REF" "GS_ASSEMBLY_REF" ON "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"="GS_ASSEMBLY_REF"."gs_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_DEFAULTS" "GS_ASSEMBLY_DEFAULTS" ON "GS_ASSEMBLY_REF"."gs_guid"="GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid"
WHERE  "ST_WORKORDER_REF"."st_wo_number"=N'90295' AND "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code"=N'C'
ORDER BY "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"I want to append the results from the subreport:
Sub Report SQL Select
SELECT DISTINCT "ST_WORKORDER_REF"."st_wo_number", "ST_WORKORDER_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid", "GS_ASSEMBLY_REF"."gs_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid", "GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_quantity", "GS_ASSEMBLY_REF"."gs_assembly_description", "GS_ASSEMBLY_REF"."gs_display_feature_name", "ST_ATTACHED_ASSEMBLIES"."gs_network_feature_name", "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code", "ST_ATTACHED_ASSEMBLIES"."gs_assembly_date_created", "ST_ATTACHED_ASSEMBLIES"."gs_display_feature_name", "ST_SPAN"."st_workorder_ref_guid"
FROM   ((("gsXXXXX"."dbo"."ST_WORKORDER_REF" "ST_WORKORDER_REF" INNER JOIN "gsXXXXX"."dbo"."ST_SPAN" "ST_SPAN" ON "ST_WORKORDER_REF"."gs_guid"="ST_SPAN"."st_workorder_ref_guid") INNER JOIN "gsXXXXX"."dbo"."ST_ATTACHED_ASSEMBLIES" "ST_ATTACHED_ASSEMBLIES" ON "ST_SPAN"."gs_guid"="ST_ATTACHED_ASSEMBLIES"."gs_network_feature_guid") LEFT OUTER JOIN "gs54025_master"."dbo"."GS_ASSEMBLY_REF" "GS_ASSEMBLY_REF" ON "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"="GS_ASSEMBLY_REF"."gs_guid") LEFT OUTER JOIN "gsXXXXX"."dbo"."GS_ASSEMBLY_DEFAULTS" "GS_ASSEMBLY_DEFAULTS" ON "GS_ASSEMBLY_REF"."gs_guid"="GS_ASSEMBLY_DEFAULTS"."gs_assembly_ref_guid"
WHERE  "ST_WORKORDER_REF"."st_wo_number"=N'90295' AND "ST_ATTACHED_ASSEMBLIES"."st_assembly_action_code"=N'C'
ORDER BY "ST_ATTACHED_ASSEMBLIES"."gs_assembly_guid"Thanks,
BTW, I realize the SQL in both are very similar. GS_station and GS_Span both starting points... why I needed the subreport.
John

Not being a Crystal Reports developer, it's not obvious to me what "subreport" means in this context.
What would it mean to you to combine the main report and the subreport? Do you just want to add the rows that the subreport returns to the end of the results returned by the report? If so, is the structure of the two report sets identical (do they select the same number of columns with the same data types)? Or do you want to join the data from the report query to the data from the subreport query? If so, what key(s) relate the rows in one to the rows in the other? Or do you want to do something else?
It would be exceptionally helpful if you could post the DDL to create your tables (simplified versions if possible), the DML to insert some reasonable sample data, and an explanation of the output you're trying to get from the combined query.
Justin

Similar Messages

  • How to join multiple SQL statements?

    I'm try to combine four of the following SQL statements as one, and I basically want to group by the new combined sql statement by suspension
    Using: Oracle 10g
    Here's my sql statements/what I've tried but doesn't seem to work:
    select *
    from
    --NBA
    select
           decode (t.league_id, 1 , 'NBA') as League,
           t.moniker as First,
           t.Last_name as Last,
           (t.To_Team_Name || ' ' || To_Team_Nickname) as Team,
           count(*) Suspensions
    from   customer_data.cd_bk_trans t,
           customer_data.cd_bk_roster r
    where  t.player_id = r.player_id
    and    t.trans_type_id in (12,13,14)
    and    r.status = 'Y'
    and    r.league_id = 01
    group by t.league_id,t.last_name, t.moniker, t.to_team_name,t.to_team_nickname
    order by Suspensions desc
    union
    --MLB
    select
           decode (t.league_id, 7 , 'MLB') as League,
           t.moniker as First,
           t.Last_name as Last,
           (t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
           count(*) Suspensions
    from   customer_data.cd_baseball_trans t,
           customer_data.cd_baseball_roster r
    where  t.player_id = r.player_id
    and    t.comments like '%Susp%'
    and    r.status = 'Y'
    and    r.league_id = 07
    group by t.league_id,t.last_name, t.moniker, t.from_team_name,t.from_team_nickname
    order by Suspensions desc
    union
    --NHL
    select
           decode (r.team_id,18, 'NHL') as League,
           t.fn as First,
           t.ln as Last,
           (t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
           count(*) Suspensions
    from   customer_data.cd_nhl_trans t,
           customer_data.cd_nhl_roster r
    where  t.player_id = r.player_id
    and    t.trans_type in (10,11,12)
    and    r.status = 'Y'
    and    r.league_id = 18
    group by r.league_id, t.ln, t.fn, t.from_team_name,t.from_team_nickname
    order by Suspensions desc
    union
    --NFL
    select
           decode (t.league_id, 8, 'NFL') as League,
           t.moniker as First,
           t.last_name as Last,
           (t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
           count(*) Suspensions
    from   customer_data.cd_football_trans t,
           customer_data.cd_football_roster r
    where  t.player_id = r.player_id
    and    t.trans_type_id in (24,25)
    and    r.status = 'Y'
    and    r.league_id = 8
    group by  t.league_id, t.last_name, t.moniker,           t.from_team_name,t.from_team_nickname
    order by  Suspensions desc
    Order by Suspensions desc

    Hi,
    Remove the ORDER BY clause in all the queries expcept lastone. Then it will work.
    You can have the ORDER BY clause in the last query of the inline view. Otherwise it will give the error.
    Run the query given below
    SELECT *
    FROM (
    --NBA
    SELECT decode(t.league_id, 1, 'NBA') AS league,
    t.moniker AS FIRST,
    t.last_name AS LAST,
    (t.to_team_name || ' ' || to_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_bk_trans t, customer_data.cd_bk_roster r
    WHERE t.player_id = r.player_id
    AND t.trans_type_id IN (12, 13, 14)
    AND r.status = 'Y'
    AND r.league_id = 01
    GROUP BY t.league_id,
    t.last_name,
    t.moniker,
    t.to_team_name,
    t.to_team_nickname
    UNION
    --MLB
    SELECT decode(t.league_id, 7, 'MLB') AS league,
    t.moniker AS FIRST,
    t.last_name AS LAST,
    (t.from_team_name || ' ' || from_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_baseball_trans t,
    customer_data.cd_baseball_roster r
    WHERE t.player_id = r.player_id
    AND t.comments LIKE '%Susp%'
    AND r.status = 'Y'
    AND r.league_id = 07
    GROUP BY t.league_id,
    t.last_name,
    t.moniker,
    t.from_team_name,
    t.from_team_nickname
    UNION
    --NHL
    SELECT decode(r.team_id, 18, 'NHL') AS league,
    t.fn AS FIRST,
    t.ln AS LAST,
    (t.from_team_name || ' ' || from_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_nhl_trans t, customer_data.cd_nhl_roster r
    WHERE t.player_id = r.player_id
    AND t.trans_type IN (10, 11, 12)
    AND r.status = 'Y'
    AND r.league_id = 18
    GROUP BY r.league_id,
    t.ln,
    t.fn,
    t.from_team_name,
    t.from_team_nickname
    UNION
    --NFL
    SELECT decode(t.league_id, 8, 'NFL') AS league,
    t.moniker AS FIRST,
    t.last_name AS LAST,
    (t.from_team_name || ' ' || from_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_football_trans t,
    customer_data.cd_football_roster r
    WHERE t.player_id = r.player_id
    AND t.trans_type_id IN (24, 25)
    AND r.status = 'Y'
    AND r.league_id = 8
    GROUP BY t.league_id,
    t.last_name,
    t.moniker,
    t.from_team_name,
    t.from_team_nickname
    ORDER BY suspensions DESC)
    ORDER BY suspensions DESC

  • How to put the SQL-statement returned value into the field (as a default)

    Hi,
    I am using Developer/2000 (Forms Designer) under windows 98.
    Please tell me how to put the SQL-statement value (as a default value) into the field before enter-query mode. Noted that I have tried the following ways but still some problems:-
    1) Place the SQL-statement into PRE_QUERY trigger in the form/block level.
    There is a message box which ask 'Do you want to save the changes?'.
    2) Place the SQL-statement before execute enter_query. There is still a
    message box which ask 'Do you want to save the changes?'.
    Any hints? Thanks. Urgent.

    solved it!
    1) Suppress DEFAULT save message
    if form_failure then
    raise form_trigger_failure;
    end if;
    2) Place the default value before enter-query.
    Ref: Title='Default value in query field in ENTER_QUERY mode' in designer forum by CVZ
    form level trigger
    ============
    WHEN-NEW-ITEM-INSTANCE
    =======================
    if :system.mode = 'ENTER-QUERY' then
    :block.item := 'default waarde';
    end if;
    3) Suppress the changes whenever leaving the default field.
    if :block.item is null then
    -- assign statement
    end if;

  • How to join THREE different tables into internal table using one select statement .

    How to join THREE different tables into internal table using one select statement .
    Hi experts,
    I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
    Scenario:
    Database tables:
    SPFLI
    SFLIGHT
    SBOOK.
    Table Fields:
    SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
    SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
    SEATSOCC_C SEATSMAX_F SEATSOCC_F
    SBOOK - CARRID CONNID CLASS
    MY INTERNAL TABLE IS IT_XX.
    Your help much appreciated.
    Thanks in advance.
    Pawan.

    Hi Pawan,
    please check below codes. hope it can help you.
    TYPES: BEGIN OF ty_xx,
            carrid     TYPE spfli-carrid   ,
            connid     TYPE spfli-connid   ,
            countryfr  TYPE spfli-countryfr,
            cityfrom   TYPE spfli-cityfrom  ,
            countryto  TYPE spfli-countryto,
            cityto     TYPE spfli-cityto   ,
            fldate     TYPE sflight-fldate ,
            seatsmax   TYPE sflight-seatsmax ,
            seatsocc   TYPE sflight-seatsocc ,
            seatsmax_b TYPE sflight-seatsmax_b,
            seatsocc_b TYPE sflight-seatsocc_b,
            seatsmax_f TYPE sflight-seatsmax_f,
            seatsocc_f TYPE sflight-seatsocc_f,
            class      TYPE sbook-class,
          END OF ty_xx,
          t_xx TYPE STANDARD TABLE OF ty_xx.
    DATA: it_xx TYPE t_xx.
    SELECT spfli~carrid
           spfli~connid
           spfli~countryfr
           spfli~cityfrom
           spfli~countryto
           spfli~cityto
           sflight~fldate
           sflight~seatsmax
           sflight~seatsocc
           sflight~seatsmax_b
           sflight~seatsocc_b
           sflight~seatsmax_f
           sflight~seatsocc_f
           sbook~class
      INTO TABLE it_xx
      FROM spfli INNER JOIN sflight
      ON spfli~carrid = sflight~carrid
      AND spfli~connid = sflight~connid
      INNER JOIN sbook
      ON spfli~carrid = sbook~carrid
      AND spfli~connid = sbook~connid.
    Thanks,
    Yawa

  • How do I use SQL statements to perform calculations with form fields????

    Please help!!! I don't know how to use a SQL statement within my APEX form......
    My form is below. The user will enter the values in the form. Click on Submit. Then we need to run a SQL select statement with those values.
    Our form looks like this:
    Start_Date ____________
    Per_Period ____________
    Period ____________
    [Submit Button]
    The user will enter these 3 values in the form.
    This is an example of an user providing the values:
    Start_Date 03/14/08_______
    Per_Period $200.00________
    Period 4____________
    [Submit Button]
    Then they will click the Submit Button.
    The SQL statement (BELOW) returns output based on the users selections:
    START_DATE PER_PERIOD PERIOD
    14-MAR-2008 00:00 200 Week 1 of 4
    21-MAR-2008 00:00 200 Week 2 of 4
    28-MAR-2008 00:00 200 Week 3 of 4
    04-APR-2008 00:00 200 Week 4 of 4
    Total 800
    This is the full text of the SQL that makes the output above:
    with criteria as (select to_date('03/14/08', 'mm/dd/rr') as start_date,
    4 as periods,
    'Week' as period,
    200 per_period from dual),
    periods as (select 'Week' period, 7 days, 0 months from dual
    union all select 'BiWeek', 14, 0 from dual
    union all select 'Month', 0, 1 from dual
    union all select 'ByMonth', 0, 2 from dual
    union all select 'Quarter', 0, 3 from dual
    union all select 'Year', 0 , 12 from dual
    t1 as (
    select add_months(start_date,months*(level-1))+days*(level-1) start_date,
    per_period,
    c.period||' '||level||' of '||c.periods period
    from criteria c join periods p on c.period = p.period
    connect by level <= periods)
    select case grouping(start_date)
    when 1 then 'Total'
    else to_char(start_date)
    end start_date,
    sum(per_period) per_period,
    period
    from t1
    group by rollup ((start_date, period))
    THANKS VERY MUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    You're just doing a parameterized report, where the input fields are your parameters.
    Check out the Advanced Tutorial titled Parameterized Report here:
    http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10497/rprt_query.htm#BGBEEBJA
    Good luck,
    Stew

  • How to run a SQL statement which is stored inside an SQL Table

    Hello,
    If anyone please help me with the following problem I would be forever grateful
    I have an SQL statement which is stored inside a certain SQL table, I want to use that SQL statement inside my PL/SQL procedure.
    Was thinking of a simple solution of obtaining the SQL statement into an array and then execute it, yet how could I do so exactly with PL/SQL? I've only started playing around with PL/SQL in the last few days.
    Thanks in advance!
    This is how it looks like more or less:
    Displaying result for:
    SELECT TRIM(OBJ_VALU_TXT)
    FROM   OBJ_VALU_DOC
    WHERE  OBJECT_TYPE  = 'FLD'
      AND  OBJECT_CODE  = 15443
      AND  OBJ_VALU_CD  = 'ACR'
    ORDER BYDOC_SEQ_NO
    00001                                                            
    SELECT
    VALUE(MAX(RECEIPT_NO) + 1, :OUT-COMP-FACTOR)
    FROM RECEIPT
    WHERE (RECEIPT_NO BETWEEN
    :OUT-COMP-FACTOR AND :OUT-TO-NUMBER) OR
    (RECEIPT_NO > :OUT-COMP-FACTOR AND
    :OUT-TO-NUMBER = 0)

    Here's a demo of your requirement.
    create table t ( col1 varchar2(200));
    table created
    insert into t values('select * from dual');
    1 row inserted
    declare
    v_col varchar2(200);
    v_val varchar2(200);
    begin
    select col1 into v_col from t;
    execute immediate v_col into v_val;
    dbms_output.put_line(v_val);
    end;
    X
    Using into clause, you can use as many variables as required. But the basic approach reamins the same.
    But storing SQL in DB is not an efficient design.
    Ishan

  • How do I separate a PDF into multiple PDFs using Adobe PDF Pack?

    How do I separate a pdf into multiple pdfs using AdobePack?
    [Title edited to reflect actual product name... Mod]

    I do not find "AdobePack" when I look at the list of forums https://forums.adobe.com/welcome
    What is the exact name of the program you are using... Acrobat, or are you using the online version at Acrobat.com?
    ADDED... found Adobe PDF Pack (read only) so will move this message

  • How to write the sql statement of my finder function in cmp?

    hi,
    I create a cmp ejb from table INFOCOLUMN,and I create a my finder function ,which sql statement is :
    select * from INFOCOLUMN WHERE employee_id=id
    employee_id is a column of the table,and id is the finder function parameter.
    The error is : invalid column name
    So,how to write the sql statement.
    Thanks .

    Mole-
    Bind variables are of the form $1, $2, etc., so your query stmt should look like:
    select * from INFOCOLUMN WHERE employee_id=$1
    -Jon

  • How can I separate one column into multiple column?

    How can I separate one column into multiple column?
    This is what I have:
    BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
    0001 PHONE_NUMBER 555-555-0001
    0001 EMAIL [email protected]
    0001 CURRENCY USD
    0002 PHONE_NUMBER 555-555-0002
    0002 EMAIL [email protected]
    0002 CURRENCY USD
    0003 PHONE_NUMBER 555-555-0003
    0003 EMAIL [email protected]
    0003 CURRENCY CAD
    This is what I would like to have:
    BUYER_ID PHONE_NUMBER EMAIL CURRENCY
    0001 555-555-0001 [email protected] USD
    0002 555-555-0002 [email protected] USD
    0003 555-555-0003 [email protected] CAD
    Any help would be greatly appreciated.

    This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
    CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
    then you will type this procedure:
    declare
    phone_number_v varchar2(50);
    EMAIL_v varchar2(50);
    CURRENCY_v varchar2(50);
    cursor my_test is select * from test;
    begin
    for my_test_curs in my_test loop
    select ATTRIBUTE_VALUE INTO phone_number_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='PHONE_NUMBER';
    select ATTRIBUTE_VALUE INTO EMAIL_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='EMAIL';
    select ATTRIBUTE_VALUE INTO CURRENCY_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='CURRENCY';
    INSERT INTO test2
    VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
    END LOOP;
    END;
    Then you will create your final table like this:
    create table final_table as select * from test2 where 1=2;
    After that write this code:
    INSERT ALL
    into final_table
    SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
    FROM TEST2;
    If you have a huge amount of data in your original table this solution may take a long time to do what you need.

  • How to assign a sql statement to a variable

    hey
    i am assigning a sql statement into a variable. But in sql statement where condition i am passing a variable, i am getting syntax error while processing this statement . Could please help me
    my code is like this
    sSql:='select id from SOURCES where name=' || vc_arr(i);
    Open C for sSql;
    ....

    If you use bind variables, you don't need the single quotes, and may avoid significant performance and security problems otherwise associated with dynamic SQL.
    sSql := 'select id from SOURCES where name = :some_value';
    OPEN C FOR sSql USING vc_arr(i);

  • Hello. i have a 57 min mts video that i'd like to cut into several short videos. simple, probably. how do i separate this video into sections?

    hello. i have a 57 min mts video that i'd like to cut into several short videos. simple, probably. how do i separate this video into sections?

    Press F1 and type in Subclips.

  • How to see all sql statements on sql commands under history link

    Hi All,
    How to see the all the sql history on sql commands tab.
    I want see all sql statements.
    Where to set if we need to store more sql statments in history.
    We are using Apex3.2 and 10g database(EE).
    Thanks,
    Nr

    I just checked the source code of the SQL commands history region and that report fetches a maximum of 1000 records. I don't know if you change the setting somewhere in the builder, but seeing the code it looks as though 1000 is hard-coded in the report definition(apex 4.0).
    If you need to see all the command history,you can query the original table: APEX_040000.WWV_FLOW_SW_SQL_CMDS
    Note that is an internal table used by apex and hence you might not find any documentation about it(google got me one valid hit: Identifying Inactive Workspaces which seem to confirm the table's use).
    Anyway, here's what you need to do, ask your dba to grant your workspace user select access on this table
    Connect as dba user and run
    GRANT SELECT ON APEX_040000.wwv_flow_sw_sql_cmds to '<WORKSPACE SCHEMA>'Now you can run the following command from your workspace to see the entire command history using
    select * from APEX_040000.WWV_FLOW_SW_SQL_CMDS where parsed_schema = '<WORKSPACE SCHEMA>';You might want to revoke the grant once you have seen the data/taken out an export due to security issues.

  • Need help on how to code this SQL statement! (one key has leading zeros)

    Good day, everyone!
    First of all, I apologize if this isn't the best forum.  I thought of putting it in the SAP Oracle database forum, but the messages there seemed to be geared outside of ABAP SELECTs and programming.  Here's my question:
    I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    Unfortunately, I don't have a lot of experience coding SQL, so I'm not sure how to resolve this.
    Please help!  As always, I will award points to ALL helpful responses!
    Thanks!!
    Dave

    >
    Dave Packard wrote:
    > Good day, everyone!
    > I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    >
    > The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    > Dave
    You can't do a join like this in SAP's open SQL.  You could do it in real SQL ie EXEC.... ENDEXEC by using SUSBTR to strip off the leading zeros from AUFNR but this would not be a good idea because a)  modifying a column in the WHERE clause will stop any index on that column being used and b) using real SQL rather than open SQL is really not something that should be encouraged for database portability reasons etc. 
    Forget about a database join and do it in two stages; get your AUFK data into an itab, strip off the leading zeros, and then use FAE to get the FMIFIIT data (or do it the other way round). 
    I do hope you've got an index on your FMIFIIT MEASURE field (we don't have one here); otherwise your SELECT could be slow if the table holds a lot of data.

  • How to execute multiple sql statements

    hi all
    i am wondering if i can execute multiple sql statements in one shot with >> execute immediate command
    for example:
    i define the variable as X := sql statement
    Y := sql statement
    z := sql statement
    can i do execute immediate (X,Y, Z);
    if yes how ?? and if not any possible alternate
    thanks

    Starting with Ganesh's code
    DECLARE
       l_statement                 VARCHAR2 (2000);
       v_passwd                    VARCHAR2 (200);
       v_username                  VARCHAR2 (200) := 'test';
       v_pwd_key                   VARCHAR2 (200) := 'lwty23';
       v_dblink_name               VARCHAR2 (2000);
       v_dblink_drop               VARCHAR2 (2000);
       v_dblink_create             VARCHAR2 (2000);
       v_dblink_check_connection   VARCHAR2 (2000);
       l_number                    NUMBER;
    BEGIN
       --<<c_instance>>
       FOR c_instance IN (SELECT *
                            FROM v_oracle_instances
                           WHERE environment = 'Developement')
       LOOP
          SELECT encpwd_owner.display_db_encpwd (v_username,
                                                 c_instance.host_name,
                                                 c_instance.instance_name,
                                                 v_pwd_key)
            INTO v_passwd
            FROM DUAL;
          v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name;
          v_dblink_create :=
                ' CREATE DATABASE LINK '
             || v_dblink_name
             || ' CONNECT TO '
             || v_username
             || ' '
             || 'IDENTIFIED BY '
             || v_passwd
             || ' USING'
             || ' ''(DESCRIPTION=
    (ADDRESS=(PROTOCOL=TCP)(HOST= '
             || c_instance.host_name
             || ')(PORT='
             || c_instance.LISTENER_PORT
             || '))(CONNECT_DATA=(SID='
             || c_instance.instance_name
             || ')))''';
          v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM';    --- Notice this change. I am simply selecting 1. That should be enough to test the database link.
          v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF';
          -- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;'
          BEGIN
              EXECUTE IMMEDIATE (v_dblink_create);
              DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created');
         EXCEPTION
            WHEN others THEN
               dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
          EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number;    --- Notice this.
          DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
          BEGIN
             EXECUTE IMMEDIATE (v_dblink_drop); 
             DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
          EXCEPTION
             WHEN others THEN
               dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
       END LOOP;
    END;But I agree with the point that others have brought up that it really doesn't make sense to create and drop a database link like this.
    Justin

  • How to set Query SQL Statement parameter dynamically in Sender JDBCAdpter

    Hi All,
    I have one scenario in which we are using JDBC Sender Adapter.
    Now in this case,we need to set Query SQL Statement with a SELECT statement based on some fields.
    This SQL statement is not constant, it would need to be changed.
    Means sometimes receiver will want to execute SQL statement with these fields and sometimes they will want to execute it with different fields.
    We can create separate channels for each SQL statement but again that is not an optimum solution.
    So ,I am looking out for a way to set these parameters dynamically or set SQL statement at Runtime.
    Can you all please help me to get this?

    Shweta ,
    <i>Sometimes receiver will want to execute SQL statement dynamically</i>....
    How you will get the query dynamically? Ok Let me assume, consider they are sending the query through file, then its definitely possible. But u need BPM and also not sender JDBC receiver adapter instead, receiver JDBC adapter.
    SQL Query File ->BPM>Synchronous send [Fetch data from DB]--->Response -
    >...............
    Do u think the above design will suit's ur case!!!!
    Best regards,
    raj.

Maybe you are looking for

  • Output could not be issued for billing doc no

    Hi All, I am getting printpreview correctly, but when i am taking print it is saying output couldnot be issued. In Devlopment it is working fine. in qulaity i am getting this error. I am getting below error message. An error occurred while output was

  • Link db results to Dropdown list and link to email

    I need to pull information from a table 'Suppliers' in an (datebase.mdb) and retrieve two items, name and email. This in itself Dreamweaver makes fairly simple. From this information I need to produce a dropdown list, again Dreamweaver makes this sim

  • "No Items Found" when connecting to database

    Recently when I connect to a SQL database and expand the tables I get a "No Items Found" message. I have verified that the data is there and another individual has no problems connecting. I have permission to access and everything is set-up correctly

  • RFC Adapter Settings - stage 3 problems

    Hi Experts,       Mine is a RFC to FILE scenerio.I am facing a strange problem. I am sending some data to the RFC through a SE38 program, but only a part of the data is reaching the SXMB_MONI! See the report program and the Remote function Module  be

  • Problem runing virtualized SAP GUI 7.1 with APP-V 5.0 SP2

    Hello, We have been try to virtualize SAP GUI 7.1 on APP-V 5 SP2, the sequencing with app-v 5 sp2 is successful and SAP can be run correctly on the sequencer machine, however, when the application is streamed to the user and run, it immediately stops