Passing variable in a select statement

Everything about this query works except I'm trying to capture the @companyid (which is a variable) into a column in my table via my select statement.
My error is Invalid column name 'A113', etc.  However it is the A113 I'm trying to insert into the first column of the table SAP_GLsummary
Can someone fix my syntax so this works.
-- retrieves a list of gl balances from all companies
truncate table sap_glsummary
declare @companyID char(6)
declare c_company cursor for
select INTERID from dbo.GP_Interid
open c_company fetch next from c_company into @companyID
while @@fetch_status = 0
begin
insert into SAP_GLsummary
exec ('select ' + @companyID + ' , [Year],[Period ID],[Account Number],[Account Description],[Credit Amount],[Debit Amount]
FROM ' +'cgygp01.'+ @companyID + '.dbo.AccountSummary')
fetch next from c_company into @companyID
end
close c_company
deallocate c_company

Try
- retrieves a list of gl balances from all companies
truncate table sap_glsummary
declare @companyID char(6)
declare c_company cursor for
select INTERID from dbo.GP_Interid
open c_company fetch next from c_company into @companyID
while @@fetch_status = 0
begin
insert into SAP_GLsummary (Col1, Col2, ...)
exec ('select ' + quotename(@companyID,'''') + ' , [Year],[Period ID],[Account Number],[Account Description],[Credit Amount],[Debit Amount]
FROM ' +'cgygp01.'+ quotename(@companyID) + '.dbo.AccountSummary')
fetch next from c_company into @companyID
end
close c_company
deallocate c_company
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles

Similar Messages

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • Using Variables in a select statement through a Database Adapter

    I was wondering how I reference a variable in a select statement through a Database Adapter.
    Ex.
    1. I have a global variable that stores an employee number
    2. I want to select an SSN # from a table based on an employee #
    variable.
    select ssn from emp where ssn = :input_variable - ????
    - how do i reference the variable - I am getting a 'missing IN or OUT parameter error?
    Any advice is much appreciated.
    ~Thanks

    I'm just wondering if anyone knows a work around so that I might be able to store a Table's FIELD name in a variable or an array[] so that I can do a query based on the decision of a loop without having to code 10 IF/ELSE statements.For instance, although the above code will not work, this code, although quite lengthy, does:
    If DataGrid1.SelStartCol = 0 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES__PUR_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 1 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VENDOR"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 2 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VEN_LOC"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 3 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TYPE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 4 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_FROM_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 5 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TO_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 6 Then
    Adodc1.RecordSource = "Select * from tblReservation order by MISC_ADJ"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 7 Then
    Adodc1.RecordSource = "Select * from tblReservation order by STATE_TAX"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 8 Then
    Adodc1.RecordSource = "Select * from tblReservation order by LOC_CHARGE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 9 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_ID"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 10 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_OP"
    Adodc1.Refresh
    End If
    Do you see where i'm going with this?
    I simple want to use a variable in the "select * from <Table> Order by <Field>"

  • How to insert variable value using select statement - Oracle function

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this.
    thanks

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this. Do not select Case_Status from inner select, so null will be inserted then after inserting it update the case status with m_caseStatus.
    Regards.

  • [php+mysql] how to use variables in a select statement?

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

  • Substitution variable in a select statement

    I have a cursor as follows:
    cursor c2 is select'word',cuel.curricular_component_name,cuel.curricular_element_name,phase,cuel.curricular_type,student_contact_hours,faculty_name,objective,cuel.curricular_component_id,cuel.curricular_element_id
    from v_cuel cuel,v_cuelse_facu facu
    where cuel.objective like '%'||vTopic||'%'
    and cuel.phase in (:CONTROL1.PHASE)
    and cuel.curriculum_year = :CONTROL1.CURRICULUM_YEAR
    and cuel.curricular_element_id = facu.curricular_element_id
    and facu.session_nbr = 1
    and faculty_name =
    (select min(faculty_name)
    from v_cuelse_facu
    where curricular_element_id = cuel.curricular_element_id
    and faculty_name not like 'TBA%')
    and cuel.curricular_element_name not in (select cuel_name from topic_search where cuel_name is not null)
    union
    select 'word',curricular_component_name,null,phase,null,null,null,objective,curricular_component_id,null
    from curricular_components cuco
    where objective like '%'||vTopic||'%'
    and cuco.phase in (:CONTROL1.PHASE)
    and cuco.curriculum_year = :CONTROL1.CURRICULUM_YEAR;
    The problem I'm having is with the bind variable :CONTROL1.PHASE. The substitution is not happening. If I replace the bind variable with an acceptable value, the query works properly. If I let forms do the substitution, I get no results from the query. Just to be sure the bind variable is correct, I copied it from one debug pass and pasted into the select statement. It's correct.
    Does anyone have any ideas about what could be happening?
    Thanks,
    Meg Colby

    > and cuco.phase in (:CONTROL1.PHASE)
    You can change the above to:
    and cuco.phase
      in(:Control1.Phase1, :Control1.Phase2, :Control1.Phase3, :Control1.Phase4)And set each of the four Phase values to the values you want (but without the quotes):
    Phase1 = I-1
    Phase2 = I-2
    Phase3 = II
    Phase4 = III
    If you want, you can create a number of :Control.Phase(n) fields, and if any one is null, it won't matter.

  • Using variables in the Select statement

    Here is my Select statement:
    Set EmpDynaset = OraDatabase.CreateDynaset("select CU_NAME,CU_CONTACT from CU where CU_Name =" & cnt, 0&)
    What's wrong with this? I'm trying to use the variable cnt. Any help? Thanks, Jeremy

    Here is my Select statement:
    Set EmpDynaset = OraDatabase.CreateDynaset("select CU_NAME,CU_CONTACT from CU where CU_Name =" & cnt, 0&)
    What's wrong with this? I'm trying to use the variable cnt. Any help? Thanks, Jeremy Perhaps using the following:
    ("select CU_NAME,CU_CONTACT from CU where CU_Name = :variable")
    then binding the variable to a value before executing the statement..

  • Please help: How to pass variable from main select to subquery

    I have a table with four columns (id, status, start_date and end_date) as follows. What I want is to get the difference between the statuses' start_date to find out how long it takes for the ID to change status. Basically getting the difference of the Start_dates of the statuses for the ID.
    ID         Status               Start_date          End_date
    1         NEW             02-FEB-07        02-FEB-07
    1         OLD             04-FEB-07        06-FEB-07
    1         BAD             09-FEB-07        14-FEB-07
    I had initially thought of doing this
    SELECT ID, (SELECT Start_date from tbl where Status = 'OLD' and ID = 1) - (SELECT Start_date from tbl WHERE Status = 'NEW' and ID =1) from tbl where ID = 1
    but that would not work since I have more than one id and implementing inside Java will be complicated. Please help me what I need to do .. Thank you

    Or this:
    SQL> CREATE TABLE t AS (SELECT 1 ID , 'NEW' status, '02-FEB-07' start_date, '02-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 1 ID , 'OLD' status, '04-FEB-07' start_date, '06-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 1 ID , 'BAD' status, '09-FEB-07' start_date, '14-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 2 ID , 'NEW' status, '02-FEB-07' start_date, '02-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 2 ID , 'BAD' status, '05-FEB-07' start_date, '10-FEB-07' end_date FROM DUAL
    UNION ALL SELECT 2 ID , 'OLD' status, '07-FEB-07' start_date, '10-FEB-07' end_date FROM DUAL
    Table created.
    SQL> ALTER SESSION SET nls_date_format='DD-MON-RR'
    Session altered.
    SQL> SELECT ID,
           status,
           start_date,
           TO_DATE (start_date)
           - LAG (TO_DATE (start_date)) OVER (PARTITION BY ID ORDER BY TO_DATE
                                                                       (start_date))
                                                               diff_of_start_days
      FROM t
                                                    ID STA START_DAT                                 DIFF_OF_START_DAYS
                                                     1 NEW 02-FEB-07                                                  
                                                     1 OLD 04-FEB-07                                                  2
                                                     1 BAD 09-FEB-07                                                  5
                                                     2 NEW 02-FEB-07                                                  
                                                     2 BAD 05-FEB-07                                                  3
                                                     2 OLD 07-FEB-07                                                  2
    6 rows selected.

  • Getting Username to pass into LOV select statement

    Hello!
    I'm wondering if its possible to get the username of the current user logged in and pass it as a variable into a select statement used in a dynamic LOV in Oracle AS Portal?
    What I'm attempting to do is pull all the values from a table that equal the current user's username to user on a portal report
    so (as a rough example)
    select color from mytable where username = 'whatever the user name is would be here'
    And then the current user would get a list of values from which to select based off of the values entered in this table.
    The issue I'm having is determing how to fill the 'whatever the user name is would be here' portion with the actual logged in user's username (or even if its possible). I know on the actual portal one can do #USER.FULLNAME# to display their username, is there a similar "variable" one may use to get the username for a LOV sql call?
    I can get it to work if I statically fix the username to a particular value (ex: where username = 'Joe.Hacker') but I'm unsure if theres a variable or bind value (for lack of a better term) to grab the username on the fly.. dynamically.

    portal.wwctx_api.get_user can be used in the SQL query of your portal report to get the user_name of the currently logged-in portal user. For more info on wwctx_api, see the 10.1.2 or 10.1.4 portal API docs at http://www.oracle.com/technology/products/ias/portal/html/plsqldoc/pldoc1012/index.html or http://www.oracle.com/technology/products/ias/portal/html/plsqldoc/pldoc1014/index.html

  • Storing variable from select statement

    I need to store a variable from a select statement into a session. Before I was taken what was passed from another page and throwing it into a session.--
    String Password= request.getParameter("Password");
    String sql = "Select WEB_USER_ID FROM Web_User WHERE PASSWORD = '" + Password +"'";
    session.setAttribute("USER",Password);
    Now though I need to put in Web_User_Id and cannot find the proper syntax. Can someone help
    session.setAttribute("User",???????);

    WEB_USER_ID is unidentified because it is a column name, not a variable name. You should first assign its value to a variable and then put the variable name into the setAttribute statement instead.
    Your query may return more than one result based on the way it is written. It sounds like you are trying to find all users with a password that is equal to the value of Password. If this is correct, then are you trying to create an attribute for each user?
    If your intention is to locate a user, then the user id and password should have been provided. A variable should be defined for both the password and user id. You should then add the user id to the where clause. After a successful search, the attributes can be created using the same syntax.

  • Using variable in select statement (php)

    I am having difficulty using a variable in a select
    statement.
    The following manual query (using a static date) works fine:
    $query_Recordset1 = "SELECT * FROM academyClasses WHERE
    classDate > '2006-06-01' ";
    However, If I use the following:
    $dateVar = date('Y-m-d');
    mysql_select_db($database_mw, $mw);
    $query_Recordset1 = "SELECT * FROM academyClasses WHERE
    classDate > $dateVar ";
    ALL records are returned, which means the $dateVar variable
    is not being recognized. I have compared the $dateVar values
    <?php echo $datetime; ?> against the actual value of my date
    field <?php echo $row_Recordset1['classDate']; ?> in my
    results table and it seems that the values are indeed accurate in
    terms of a date 2006-06-04 for example.
    My date field "classDate" is of a "date" type within the
    mysql database. I'm using Dreamweaver MX 2004 with Mac OSX 10.3.9.
    I'm sure this is just a syntax problem, at least I hope it
    is.
    Any help is greatly appreciated.

    On Wed, 7 Jun 2006 04:49:57 +0000 (UTC), "mgwaters"
    <[email protected]> wrote:
    >Thanks Gary. That did seem to get the select statement
    working, but I had to
    >enter a manual date as before $dateVar = '2006-06-01'; on
    the previous line of
    >code to actually get it to filter my records. So... it
    looks like my setting of
    >the date variable:
    > $dateVar = date('Y-m-d');
    > does not seem to be recognized within the SELECT
    statement.
    Try this:
    $query_Recordset1 = "SELECT * FROM academyClasses WHERE
    classDate>'$dateVar'";
    print $query_Recordset1;
    See what is in the SQL statement.
    Gary

  • How to pass output from one selection-as input to another selectiion??

    From a user prompt will iniate many user table selections.   And  the outputs  of each table selection will be used as inputs for the next table selection
    I reviewed variable Scope and inner and outer Declare—it would be a great help if some one could give me a  example of the right approach??
    see sample script :
    Thank you so much for your help
    ---------------------------- Section_01_UserInput.sql -------------------------
    -- THIS SECTION OF THE SCRIPT IS TO PROMPT THE USER FOR THE MODEL NAME AND THE ORGANIZATION CODE (e.I...M1,M2,M3...._)
    -- THE ORGANIZATION WHERE MODEL WAS CREATED IS THE ONLY PLACE WHERE YOU WOULD FIND THE BILL_SEQUENCE_ID
    -- THE COMMON ORGANIZATIONS DO NOT HAVE COMPONETS THEY JUST REFERENCE TO THE ORHANIZATION THAT MODEL WAS CREATED
    SET VERIFY OFF
    SET ECHO OFF
    ACCEPT v_assemblyName CHAR DEFAULT myDefaultAssemblyName PROMPT 'Enter Assembly name:'
    ACCEPT v_OrganizationCode CHAR DEFAULT myDefaultOrganizationCode PROMPT 'Enter the Org where the MODEL WAS CREATED :'
    SELECT a.organization_code, a.organization_id, b.inventory_item_id, b.segment1, b.description
    FROM mtl_parameters a, mtl_system_items_b b
    WHERE a.organization_code = '&v_OrganizationCode'
    AND
    b.segment1 ='&v_assemblyName'
    AND
    b.organization_id = a.organization_id;
    SET VERIFY ON
    SET ECHO ON
    ----OUTPUT of the Section_01_UserInput.sql QUERY---
    ORGANIZATION_CODE ORGANIZATION_ID INVENTORY_ITEM_ID SEGMENT1 DESCRIPTION
    M1, 207, *[225957]* , CN927779, Sentinel Custom Desktop
    ----------------------------- Section_02_bom_structures_b.sql ------------------
    -- List all option class Bill of Materials for a single ATO or PTO model
    -- List of bill_sequence_id and all component_item_id's that belong to that
    -- bill_sequence_id
    SELECT a.assembly_item_id, a.bill_sequence_id, b.bom_item_type, b.component_item_id
    FROM bom_structures_b a, bom_components_b b
    WHERE a.assembly_item_id = *['225957']*
    AND
    b.bill_sequence_id = a.bill_sequence_id
    AND
    b.bom_item_type = '2'; -- OPTION Class's are identified by bom_item_type
    ----OUTPUT of the Section_02_bom_structures_b.sql  QUERY---
    ASSEMBLY_ITEM_ID ORGANIZATION_ID BILL_SEQUENCE_ID BOM_ITEM_TYPE BILL_SEQUENCE_ID COMPONENT_ITEM_ID
    *[225957]* , 207 , *[90754]* 2 90754 *[297]*
    *[225957]* , 207 , *[90754]* 2 90754 *[299]*
    *[225957]* , 207 , *[90754]* 2 90754 *[301]*
    ----------------------------- Section_03A_bom_structures_b.sql-------------------
    -- List all the components under the option class
    -- When no components are found with bom_item_type ='4' which means that this assembly has no
    -- components in the bom_components_b because the assembly is a child that is a option class.
    -- We need to run this script with a bom_item_type ='2' and stored the component_item_id into MEMORY_assembly_id
    -- and run script again by read from MEMORY_assembly_id and bom_item_type = '4';
    SELECT a.assembly_item_id, a.organization_id, a.bill_sequence_id, b.bom_item_type, b.bill_sequence_id, b.component_item_id
    FROM bom_structures_b a, bom_components_b b
    WHERE a.assembly_item_id = '297'
    AND
    b.bill_sequence_id = a.bill_sequence_id
    AND
    b.bom_item_type = '4';
    ----OUTPUT of the Section_03A_bom_structures_b.sql QUERY---
    ASSEMBLY_ITEM_ID ORGANIZATION_ID BILL_SEQUENCE_ID BOM_ITEM_TYPE BILL_SEQUENCE_ID COMPONENT_ITEM_ID
    *[297]* 207 *[384]* 4 384 *[185]*
    *[297]* 207 *[384]* 4 384 *[241]*
    *[297]* 207 *[384]* 4 384 *[249]*
    *[297]* 207 *[384]* 4 384 *[4747]*
    *[297]* 207 *[384]* 4 384 *[4749]*
    *[297]* 207 *[384]* 4 384 *[4751]*
    =================================================================================================
    note output FROM EACH SELECT  that needs to be passed to the next SELECT statement are *[ ]* for example *['225957'] see below:*
    ----OUTPUT of the Section_01_UserInput.sql QUERY---
    ORGANIZATION_CODE ORGANIZATION_ID INVENTORY_ITEM_ID SEGMENT1 DESCRIPTION
    M1, 207, *[225957]* , CN927779, Sentinel Custom Desktop
    ----OUTPUT of the Section_02_bom_structures_b.sql  QUERY---
    ASSEMBLY_ITEM_ID ORGANIZATION_ID BILL_SEQUENCE_ID BOM_ITEM_TYPE BILL_SEQUENCE_ID COMPONENT_ITEM_ID
    *[225957]* , 207 , *[90754]* 2 90754 *[297]*
    *[225957]* , 207 , *[90754]* 2 90754 *[299]*
    *[225957]* , 207 , *[90754]* 2 90754 *[301]*
    ----OUTPUT of the Section_03A_bom_structures_b.sql QUERY---
    ASSEMBLY_ITEM_ID ORGANIZATION_ID BILL_SEQUENCE_ID BOM_ITEM_TYPE BILL_SEQUENCE_ID COMPONENT_ITEM_ID
    *[297]* 207 *[384]* 4 384 *[185]*
    *[297]* 207 *[384]* 4 384 *[241]*
    *[297]* 207 *[384]* 4 384 *[249]*
    *[297]* 207 *[384]* 4 384 *[4747]*
    *[297]* 207 *[384]* 4 384 *[4749]*
    *[297]* 207 *[384]* 4 384 *[4751]*
    Edited by: user612347 on Mar 16, 2010 4:21 PM
    Edited by: user612347 on Mar 16, 2010 4:57 PM

    Hi,
    Sorry, it's unclear what you want to do.
    Whenever you have a problem, it helps to be as specific as you can.
    Post a little sampel data (CREATE TABLE and INSERT statements) and the results you want from that data. Since your problem involves parameters, give a couple of sets of parameters, and the results you want for each set, given the same data.
    Are you saying that, after the user enters one set of parameters, you will need to run a variation of this query:
    SELECT  a.assembly_item_id, a.organization_id, a.bill_sequence_id, b.bom_item_type, b.bill_sequence_id, b.component_item_id
    FROM    bom_structures_b a, bom_components_b b
    WHERE   a.assembly_item_id = '303'
    AND
            a.organization_id = '207'
    AND
            b.bill_sequence_id = a.bill_sequence_id
    AND
            b.bom_item_type = '4';several times? What will be different each time? Will the hard-coded strings in the WHERE clause ('303', '207' and '4') be values from the earlier query?
    Do you really want to run this query several times, or would you rather run one query, and have it produce results for all the relevant values? (That would probably be eaisest and less error-prone). When you post your desired results, post what you would most like to see. If something else is acceptable, describe it.
    You can write SQL*Plus scripts to use parameters (substitution variables.
    For example, you can write a query that says:
    WHERE   a.assembly_item_id     = '&1'
    AND     a.organization_id      = '&2'
    AND     b.bill_sequence_id      = a.bill_sequence_id
    AND     b.bom_item_type      = '&3';and call it like this
    @Section_03A_bom_structures_b  303  207  4You can have a query output several such rows (for example:
    @Section_03A_bom_structures_b  303  207  4
    @Section_03A_bom_structures_b  304  298  3
    @Section_03A_bom_structures_b  306  99   4), send all of that output to a SPOOL file, and then execute the SPOOL file.

  • Select statement from "v_filename_txt" inside cursor

    Hi,
    I've got a store procedure procedure that create parametric tables to upload from csv files. I have collect into v_filename_txt variable the parametric table name where I would like to make some select.
    I have write the following code but I can't use a variable into a select statement :
    select field
    FROM TABLE '''||v_filename_txt||''' ;
    Does anybody know how to include the precedent statement into a cursor to retrive recods ?
    Paolo.

    You could rcreate an external table. Then select the values from this external table.
    You can switch the source of the external table to a new file with the
    alter table myExtTable location ('mySecondCsvFIle.csv');
    command.
    Of cause this works only when all the files have the same structure. But the Idea is: mimic the structure of the csv file sin the database with a external table command. Then you can read the values and move them to some other table.
    Insert into myParameterTable select * from myExtTable;

  • How can i pass a variable instead of a table name in the Select statement.

    Dear all
    how can i pass a variable instead of a table name in a select statement ?
    Example :-
    Begin
    P_get_procedure_tname (aap_name,otable_name);--It will take an application name and will return a table name
    Select col1 into ocol1
    from  ---- here i want to pass the variable OTABLE_NAME
    End;How can i pass this ?

    Hi,
    You can use dynamic sql.
    EXECUTE IMMEDIATE 'SELECT COL1 INTO ' || OCOL1 || ' FROM " || OTABLE_NAME;
    {code}
    cheers
    VT                                                                                                                                                                                                                                                                                                   

  • Passing a variable to select statement

    Hi there,
    I have a selection screen on which you can choose which table do you want to display.
    I store the name of the selected table in a variable tab_name.
    I want to use something like that:
    data: tab_name(40).
    select * from tab_name
        into gt_master.
    endselect.
    But it did not allowed because tab_name is not a database table.
    Is it possible to pass the table name in a select statement using a variable?

    Hello
    Yes it is posible you can use a dynamic select...
    Try this:
    DATA  tabname(10).
    DATA: BEGIN OF wa,
            id   TYPE scustom-id,
            name TYPE scustom-name,
          END OF wa.
    tabname = 'SCUSTOM'.
    SELECT id name INTO CORRESPONDING FIELDS OF wa FROM (tabname).
      WRITE: / wa-id, wa-name.
    ENDSELECT.
    or
    CONSTANTS: flight_tab_name(30) VALUE 'SPFLI'.
    DATA: from_clause TYPE STRING.
    DATA: BEGIN OF wa,
            name(20) TYPE C,
            connid   TYPE spfli-connid,
          END OF wa.
    CONCATENATE flight_tab_name ' AS t1'
                ' JOIN scarr AS t2 ON t1carrid = t2carrid'
       INTO from_clause.
    SELECT t1connid t2carrname AS name
        FROM (from_clause)
        INTO CORRESPONDING FIELDS OF wa.
      WRITE: / wa-name, wa-connid.
    ENDSELECT
    Hope this helps
    Gabriel

Maybe you are looking for

  • Can I stream video from my mac to apple tv the same way my ipad or ipod does?

    I just got my AppleTV hoping to stream video to it from my iMac.  I'm seeing this is possible with mirroring, but there was a ton of lag between the computer and tv, and the sound and video would skip horribly.  I plugged the ATV into our ethernet an

  • Foreign key not working in a table control set on a pop-up window

    Hi Experts, I have created a table control using EEWB on BUPA object. I have moved this table control using BUCO transaction to address view. As the address is displayed in BP transaction as a pop-up window, when the error message from the foreign ke

  • My iPod touch 4th gen doesn't charge.

    My iPod touch 4th gen doesn't charge. Sometimes it will charge fine but then other times it will say "charging is not supported with this accessory"

  • FAQ: How can I create a scrolling gallery of images?

    You can use Flash Catalyst to create galleries, for example a scrolling list of thumbnails that display larger images when clicked. Here are some tutorials that explain how: Create a photo gallery (using list interactions), on the FlashCats blog Crea

  • Mrp run to do  for different numbers in a sale order

    Dear Sir, we are doing make to order planning strategy 20  and receiving sale order on august 2008 of 7 nos and delivery date  is of 21 july 2009. my  client needs to do mrp run  as per the client planned date  , but in md04 the sale order is showing