INNER join with dynamic table name ?

Hi,
I have a problem with this statement.
DATA: g_dso_bic_dofr TYPE tabname.
SELECT t1~/bic/ziparomr
       t2~/bic/zifremom
INTO (wa_rater_paromr-/bic/ziparomr,
       wa_rater_paromr-/bic/zifremom)
*   FROM /bic/azd0bfr5100 AS t1     "equivalent to the dynamic statement below
" this is the  problem
    FROM (g_dso_bic_dofr )AS t1
    INNER JOIN /bic/pzifremom AS t2
      ON t1~/bic/ziparomr = t2~/bic/ziparomr
" --- to here
    WHERE t1~/bic/zikom     =  v_kommune
The compile check doesnt work when i use the variable table name.
I get
"Wrong expression "INNER" in FROM clause. WHERE condition."
Can anyone help me.
Br Rasmus.

" this is the  problem
*    FROM (g_dso_bic_dofr )AS t1   "<<--- check spaces in here
    FROM (g_dso_bic_dofr) AS t1    "<<--- and here
    INNER JOIN /bic/pzifremom AS t2
      ON t1~/bic/ziparomr = t2~/bic/ziparomr
" --- to here
I think there's the problem, the space behind the parenthesis.
Regards

Similar Messages

  • Problem with Dynamic Table Name

    Hello all,
    I am having trouble using a dynamic table name. I have the following code.....
    declare l_cur sys_refcursor;
    l_ID int;
    l_tableName varchar(30);
    BEGIN
    open l_cur for
    select hkc.ColumnID, mapping from &HKAPPDB_Schema_Name..doctablemapping ddm
    inner join &HKDB_Schema_Name..HKColumns hkc on hkc.doctablemappingid = ddm.id
    where ddm.id > 0;
    LOOP
         FETCH l_cur into l_ID, l_tableName;
         EXIT WHEN l_cur%notfound;
         -- update missing VerbID in DocumentDocMapping table
         UPDATE &HKAPPDB_Schema_Name..IndexedDocument
         SET VerbID = (SELECT t.VerbID
                             FROM (SELECT DocRef, VerbID, DateUpdated
                                  FROM &HKAPPDB_Schema_Name..l_tableName dd        - this is where the dynamic table name is used
                                  WHERE dd.VerbID is not NULL))
         WHERE HKColumnID = l_ID AND VerbID is NULL;
    END loop;
    end;
    /When I try to execute this i get an error
    ORA-00942: table or view does not exist
    What am I doing wrong?
    Regards,
    Toby

    redeye wrote:
    I only started about 6 weeks ago, with no tutorials and learning it on the fly; Same here.. only my introduction was to a 12 node Oracle OPS cluster all those years ago.. and required a whole new mind set after using SQL-Server extensively. But it was fun. Still is. :-)
    but thats what you get when a company throws you in at the deep end with a ridiculous time constraint to migrate a whole MSSQL DB.Migrating SQL-Server to Oracle is not a simple thing. A lot of best practices in SQL-Server are absolutely worse practices in Oracle - they are that different. Simple example is lock escalation - an issue in SQL-Server. In Oracle, the concept of a lock being escalated into a page lock simply does not exist.
    In terms of getting the migration done as quickly and painlessly as possible I try to reuse all the logic as it appears in the MSSQL code - in this case it was using dynamic table names. I do not doubt that i am probably shooting myself in the foot in the long run.....As long as you do not splatter too much blood on us here.. not a problem :D
    Seriously though - just keep in mind that what works in SQL-Server may not work as well (or even at all) in Oracle. So do not hesitate to refactor (from design to code to SQL) mercilessly when you think it is warranted.

  • List Region with Dynamic Table name

    Trying to build a page that is similar to Query Builder. On the left side of my page, I need to populate a list of table names from a SQL statement. Once the list is created, will need to perform some addtional actions when user clicks onthe specific row in the list.
    What is the best way to create the list (based on SQL) that will allow me to be call some addtional processing when user clicks on the specific row?
    Thanks!

    " this is the  problem
    *    FROM (g_dso_bic_dofr )AS t1   "<<--- check spaces in here
        FROM (g_dso_bic_dofr) AS t1    "<<--- and here
        INNER JOIN /bic/pzifremom AS t2
          ON t1~/bic/ziparomr = t2~/bic/ziparomr
    " --- to here
    I think there's the problem, the space behind the parenthesis.
    Regards

  • Create table with dynamic table name.

    I'm trying to create a table
    like
    select x.*,  convert(nvarchar(20), getdate(), 101) AS LoadDate
    into table1_20140512
    from (
           select c1,c2,c3 from table2_20140512
           WHERE(LoadDate = (select MAX(LoadDate) FROM table2_20140512   )
           union all
        select c1,c2,c3 from table3_20140512
          WHERE(LoadDate = (select MAX(LoadDate) FROM table3_20140512  )
    ) X
    I want to make table name dynamic, like 'table1'+toady's date
    I declared three variables, but they didn't work as I expected  
    These are my variables
    DECLARE @table1 nvarchar(500)
    DECLARE @table2 nvarchar(500)
    DECLARE @table3 nvarchar(500)
    SET @table1='H1_' +(CONVERT(VARCHAR(8),GETDATE(),112))
    SET @table2='H2_' +(CONVERT(VARCHAR(8),GETDATE(),112))
    SET @table2='H3_' +(CONVERT(VARCHAR(8),GETDATE(),112))

    Try the following:
    DECLARE @SQL nvarchar(2000);
    DECLARE @table1 nvarchar(500) ='H1_' +(CONVERT(VARCHAR(8),GETDATE(),112));
    DECLARE @table2 nvarchar(500) ='H2_' +(CONVERT(VARCHAR(8),GETDATE(),112));
    DECLARE @table3 nvarchar(500) ='H3_' +(CONVERT(VARCHAR(8),GETDATE(),112));
    PRINT @table1+' '+@table2+' '+@table3;
    --H1_20140512 H2_20140512 H3_20140512
    SET @SQL = 'select x.*, convert(nvarchar(20), getdate(), 101) AS LoadDate
    into '+QUOTENAME(@table1)+'
    from (
    select c1,c2,c3 from table2_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM '+QUOTENAME(@table2)+' ))
    union all
    select c1,c2,c3 from table3_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM '+QUOTENAME(@table3)+' ))
    ) X '
    PRINT @SQL; -- debugging
    /* select x.*, convert(nvarchar(20), getdate(), 101) AS LoadDate
    into [H1_20140512]
    from (
    select c1,c2,c3 from table2_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM [H2_20140512] ))
    union all
    select c1,c2,c3 from table3_20140512
    WHERE(LoadDate = (select MAX(LoadDate) FROM [H3_20140512] ))
    ) X
    EXEC sp_executeSQL @SQL;
    Dynamic SQL examples:
    http://www.sqlusa.com/bestpractices/dynamicsql/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Dynamic table name in an inner join - select statement

    Hi,
    Please can you let me know if is possible to use a Dynamic table name in an inner join?
    Something like the statement below? (It works in a simple select statement but not in an inner join)
    SELECT  *
         INTO CORRESPONDING FIELDS OF <t_itab>
          FROM <Dynamic table name> INNER JOIN pa0050 ON
          ( <Dynamic table name>pernr =  pa0050pernr )
           WHERE <Dynamic table name>~pernr = it_pernr-l_pernr
           AND pa0050~bdegr = f_bdegr.
    Any help would be apprecited very much.
    Thanks & Regards.

    Hi,
    Check this link.
    [http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
    [Re: accessing dynamic internal table's fields??;
    hope it'll help u.
    Regards,
    Sneha.
    Edited by: sneha kumari on Jun 18, 2009 1:57 PM

  • Dynamic Table name in Inner Join in  4.6c

    data: tab1(10) type c value 'MARA',
            tab2(10) type c value 'MAKT'.
    data: dbtab1(10) type c,
             dbtab2(10) type c .
    dbtab1 = tab1. 
    dbtab2 = tab2. 
    DATA: BEGIN OF itab occurs 0,
               matnr TYPE mara-matnr,
               maktx type makt-maktx,
    END OF itab.
    DATA: column_syntax TYPE string,
                dbtab_syntax TYPE string.
    PARAMETERS: p_matnr TYPE mara-matnr.
    dbtab_syntax = '( (dbtab1) AS t1 '
    &' INNER JOIN (dbtab2) AS t4 ON t1MATNR = t4MATNR )'.
    SELECT  matnr maktx
    FROM (dbtab_syntax)
    INTO TABLE itab  WHERE t4~matnr   = p_matnr.
    Got the following error:
    "A table name, specified in an SQL command, is unknown"
    It seems not able to read dynamic table name in dbtab_syntax.
    thanks
    anya
    Moderation Message: Duplicate Post.
    Edited by: kishan P on Nov 29, 2010 11:17 AM

    Hi,
    Check this link.
    [http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
    [Re: accessing dynamic internal table's fields??;
    hope it'll help u.
    Regards,
    Sneha.
    Edited by: sneha kumari on Jun 18, 2009 1:57 PM

  • Data model with a dynamic table name

    Hi,
    I have report requirement, where in the table name in the data model query is unknown.So I use lexical parameter like " select * from &P_TABLE_NAME". This dynamic table is created and data populated in the before report trigger and table name is assigned to P_TABLE_NAME. The parameter P_TABLE_NAME has to be assigned an initial value otherwise the report errors with 'invalid table name' error. So I give a dummy table say 'DUMMY' as the initial value which has the same structure (with no data ) as the table that is being created in the before report trigger.
    The problem is that the data model query is being parsed ( and maybe executed ) even before the 'before report' trigger is run. As a result, the report o/p is empty, since the query used the DUMMY table for execution. But after the report completes, I can see the dynamic table being created with data.
    Question: Why is the before report trigger getting executed after the datamodel query is parsed and executed.
    Regards,
    Suresh

    Hi....
    yes, these are the settings I have:
    server folder: /Applications/MAMP/htdocs/dwphpelclasico
    web url:  http://localhost/dwphpelclasico/
    They should be correct. But I still get the message:
    Warning:  require_once(Connections/elclasico.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/dwphpelclasico/list.php on line 1
    Could it be something with list.php?
    This is a new file I created to display my tableand  where I am inserted the record set.
    thanks

  • Avoid duplicates when i join with bridge table

    i have a requirement with many to many relations between fact and dimention,that is the reason we have created bridge tables in the database.
    if i execute only query on the fact table it is giving correct results.when ever i join with bridge tables it is returning lot of duplicate records.
    Ex:
    select amount from fact where column = 'xyz'
    100
    then it is returing one record.(this value is correct)
    when ever i join this fact table with bridge table then it is returning duplicate records.
    select a.amount from fact inner join bridge table b on a.fk=b.fk
    100
    100
    100
    100
    100
    how many number of fk's associated that many 100's are generating
    in this case it is returning duplicate records.
    in the RPD i have joined like one to many between fact to dimention.
    if anybody face this type of situation please let me know how to resolve this?(FYI...i would have to do this before BM..because lot of other thing are coming into picture on BMM that's why i should have to achieve this in either physical or in database.
    Thanks in advance
    Edited by: user12077461 on Apr 3, 2011 6:39 PM
    Edited by: user12077461 on Apr 17, 2011 4:51 PM

    I understand what you say but partially.. please explain in more detail how to do that;
    How should look the adrese_nezonate block, then? I have to add a 'name' column and set copy value from item property to 'STREETS.NAME', and database_property No?
    Then the post-query trigger how should look like (the order by clause)? The post-query sends the entire query (with where/order by clauses) to the server, but in that "select... where... order by" (built dynamically) there are only columns from that block (adrese_nezonate). I need to join with streets, INSIDE that query.
    Thanks.

  • Inner Join for Dynamic Select statement

    Hi All,
      Can some one please help me in rewriting the below select statement where i have to remove the existing table1 by putting a dynamic table name which has the same table structure.
      select a~zfield1
               a~zfield2
          from ztab1 as a
           inner join ztab2 as b
               on b~ztab1-zfield3 = a~ztab2-zfield3
         where a~zfield4 = 'A'.
    I am looking something as below. But encountering an error when using the below statement
      select a~zfield1
               a~zfield2
          from (v_ztab1) as a
           inner join ztab2 as b
               on b~ztab1-zfield3 = a~ztab2-zfield3
         where a~zfield4 = 'A'.
      No Separate selects please. Please help me in rewriting the same select statement itself.
    Regards,
    PSK

    hi,
    What error you are getting ?
    Also INTO is missing from the statement.
    SELECT  pcarrid pconnid ffldate bbookid
      INTO  TABLE itab
      FROM  ( spfli AS p
                INNER JOIN sflight AS f ON pcarrid = fcarrid AND
                                           pconnid = fconnid    )
      WHERE p~cityfrom = 'FRANKFURT' AND
            p~cityto   = 'NEW YORK' .
    thanks

  • Join with another table in pre-query

    Hi,
    We have a large data block and we need to order some columns based on street name for example, not id. The base table of db block contains an id_street column, and 'streets' table contains id and name.
    Ok, in pre-query trigger of that block, we have a complex logic and we dynamically build the where clause. At the end, we set the order_By clause of the block, to order the rows, for example we need to order by the 'my_date' column asc (it's a date type column), and street desc; but street NAME, not id. We don't want to use a from clause query, because the dynamically where clause logic it's complex.
    How can we join the db block table with 'streets' table in pre-query, so when constructing the order by clause to specify something like
    set_block_property('ADRESE_NEZONATE', order_by, 'my_date, name desc');where 'name' is the name of the street, from the 'streets' table.
    Is it possible in pre-query, somehow? Or, in my case where can I join with that table and use that column in pre-query at setting order by?
    Thanks!
    Edited by: Roger25 on 26.04.2013 12:31

    I understand what you say but partially.. please explain in more detail how to do that;
    How should look the adrese_nezonate block, then? I have to add a 'name' column and set copy value from item property to 'STREETS.NAME', and database_property No?
    Then the post-query trigger how should look like (the order by clause)? The post-query sends the entire query (with where/order by clauses) to the server, but in that "select... where... order by" (built dynamically) there are only columns from that block (adrese_nezonate). I need to join with streets, INSIDE that query.
    Thanks.

  • Inner Join of 3 tables is correct or not?

    Hi Guys ,
                 I have a requirement where i have to join 3 tables i  dont know whether the inner Join which i wrote for 3 tables is correct or not.I am not getting any Syntax error but whether the logci below which i wrote gets all the records or not.
    The Requirement is
    "c.     Select the BOL Number entered in the screen and query the table LIKP with the BOL number in the field LIKP-BOLNR.  Gather the list of ALL delivery documents (LIKP-VBELN) that is outputted.
    d.     Query the list of the delivery documents obtained into the table VBFA in the field VBFA- VBELV.  From the output that is displayed, select the Follow-On Document Field (VBFA-VBELN) for that item whose Subsequent Document Category (VBFA- VBTYP_N) is R and the Movement Type (VBFA- BWART) is 641.  Get the Follow-On document number for each of the above Delivery Document number.
    e.     Query the table EKBE with the Follow On document obtained above in the field Material Document (EKBE- BELNR).  Perform this activity for each of the follow on document obtained above.  Get the resultant Purchase Order (EKBE-EBELN) and Item Number (EKBE-EBELP) from the query.  After querying will all the Follow-On Documents, get the unique list of PO number and Item Number.
    The logic which i wrote is
                    Begin of t_PoolSTO_out,
                  BOLNR type LIKP-BOLNR,
                  EBELN type EKBE-EBELN,
                  EBELP type EKBE-EBELP,
                  VBELN type LIKP-VBELN,
                  VBELNV type VBFA-VBELN,
             End of t_PoolSTO_out.
          Data: i_PoolSTO type Standard table of t_PoolSTO_out.
      Select
            a~BOLNR
            c~EBELN
            c~EBELP
            a~VBELN
            b~VBELN
            from LIKP as a
            Inner Join VBFA as b on aVBELN = bVBELV
            Inner Join EKBE as c on bVBELN = cBELNR
            into Table i_PoolSTO
            Where a~BOLNR in S_LBLNE and
                  b~VBTYP_N = 'R' and
                  b~BWART = '641'.
              My doubt is whether the logic works or not i Mean does i getall the rrecords based on the requirement.?
                      If not please tell any alternative logic?
    Thanks,
    Gopi Anne.

    Hi Gopi,
    Your code is Good.
    But try to avoid Inner join with more number of Tables ...because this is a performance issue..
    try to use..
    select (primary key fields mainly,other fields) from LIKP into itab where bolnr in p_bolnr(paramater).
    next try to use for all entries option..
    select (primary key fields mainly,other fields) from VBFA for all entries in itab where (give the condition)....
    simillarly do for the other select ....ok this will try to reduce the performance issue....
    <b><REMOVED BY MODERATOR></b>
    Message was edited by:
            Alvaro Tejada Galindo

  • How to set dynamic table name in sql query?

    I want set dynamic table name by parameter in sql query,just like:
    select * from :tbname
    but run report is error,BI P report table name is invalidation.
    What can i do? Thanks!

    Hi,
    that's only possible inside a data template with a lexical parameter.
    Regards
    Rainer

  • Export with dynamic file name

    Hi everyone.
    I want to know how export oracle tables with dynamic file name on windows XP platform.
    bye.

    You'd have to generate the export command-line or par file using a script -- Windows or SQL !
    It would be easy to use SQL to generate the script.
    So you could have a BATch file that
    a. Calls the SQL to generate the export command-line or parfile
    b. Executes the export
    even possibly run in a loop.
    Hemant K Chitale

  • Passing dynamic table name in ADO. net destination

    I am new to SSIS and I have a requirement where i need to pass dynamic table name in ADO .net destination .
    My package contains an "Execute Sql task" in the control flow which computes the destination table name to be provided at run time and stores it in a variable expression
    "@[User::Table_name]"(which has a scope of full package). 
    Now, the problem I'm facing right now is that , I am unable to use this variable expression in the ADO .Net Destination .
    I need to pass this variable expression as the table name in ado .net destination.
    But, whenever I use this variable in place as the table name I keep on getting this error and my package fails:- 
    [ADO NET Destination [403]] Error: The Table or View name is not expected. \n\t If you are quoting the table name, please use the prefix " and the suffix " of your selected data provider for quotation. \n\t If you are using multipart name,
    please use at most three parts for the table name. 
    Although ,I am able to run my package when i am providing the existing(static) table name.So there is nothing wrong with the  package.
    Tried a lot of things still not working..Please help...

    I am having the result stored in the variable expression . I just need a way to be able to use it as the Destination table in ADO .net Destination.
    I am not sure if this will work for you, but I am able to store the table name in variable and use it dynamically (via data flow task expression property ) as shown.
    Thanks, hsbal
    Hi Adeep,
    Based on my further research, just as hsbal said, we can set a variable as ADO.NET Destination table via Expressions property in Data Flow Task.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Dynamic table name from Arguments in cfquery /

    I'm trying to use dynamic table names in a cfc but seem to
    have hit upon a wall as my calling methods from flash keep hitting
    my _error methods - Code attached to show what I'm trying to
    achieve; if anyone can give me some pointers it would be a great
    help. I've seen numerous by using the Form with the arguments but
    this is coming into a gateway used by a flash component and doesn't
    work no matter how much I fiddle the code.
    Thanks in advance

    There was a time when I needed a dynamic query such as this.
    BUT, it is very dangerous, which is why I took a few steps to make
    it more secure.
    1. Always use cfqueryparam and strict datatyping
    2. Use listFindNoCase for known table names in the database
    e.g
    <cfset variables.tableNames =
    "items,products,categories,blog" />
    <cfif
    listContainsNoCase(variables.tableNames,lCase(trim(arguments.tableName)),",")>
    query here
    <cfelse>
    Error: Unknown table requested
    </cfif>
    Mikey

Maybe you are looking for

  • Axis Type Mapping problem,please help!!!

    i want to try out the encoding subsystem of axis,so i write an interface like this: public interface BookStore {     public Book[] getAllBooks(); }I use the Java2WSDL to generate the wsdl file and WSDL2Java to generate the client/server side bindings

  • I cant get my macbook (2008 model running 10.6.8) to connect to the home hub 5

    to connect to the home hub 5 it connects eventually but is extremely tempermental... does anyone have a fix that doesnt involve messing around with the home hub settings... for further notes, my dads macbook (same model but running 10.7) connects and

  • AppleCare on my 20" Display - Transferring

    I purchased a PowerMac and 20" Cinema Display about 6 months ago and purchased AppleCare for both products (actually for the PowerMac and the display was included because purchased at the same time). I recently sold the PowerMac to one individual and

  • Please suggest a select query / sub query with out using any subprograms or

    source table: Three columns ORIGIN, DESTINATION,MILES Origin      Destination Miles Sydney      Melbourne      1000 Perth      Adelaide      3000 Canberra      Melbounre      700 Melbourne      Sydney           1000 Brisbane      Sydney           100

  • Wireless netwrok help

    Hi, I appologise if this has been posted before. I am having trouble connecting to the internet using a wireless connection. I have been online before using the computer although i may have deleted some stting by accident. I now try and connect via a