SQL Server Store Procedure, selecting rows from multiple tables

i have got a store procedure that is pulling data from one table, now i have got the same data collected in a different table,
as the IDs are different i cannot put all data from the second table into the first one. so now i have to have two select statements in one store procedure. Although the corresponding data is same but the field names in both table are different. for instance
BRIEF_TITLE would be briefTitle in the second table. how can i merge the data from two different tables into one. the result is bonded to ASP.net grid view control.

>> I have a store procedure that is pulling data from one table, now I have got the same data collected in a different table, as the IDs are different I cannot put all data from the second table into the first one. <<
This is redundancy. The idea of databases even before RDBMS, was to remove redundancy. Oh, columns are not fields. These are basic concepts. 
>> so now I have to have two select statements in one store procedure. Although the corresponding data is same but the field [sic] names in both table are different.<<
NO! Where is your data dictionary that assures data elements have one and only one name everywhere in the enterprise!  You are is serious trouble here. The data element names should be universal and used everywhere with the same casing, so that case sensitive
standards will work. 
>> for instance BRIEF_TITLE would be briefTitle in the second table.<< 
The quick kludge is a VIEW with the ISO-11179 names over the camelCase crap
The moron who did the second table does not know ISO-11179 Standards and missed the research that showed us that camelCase does not work. Your eye is trained to jump to an Uppercase letter since it is the start of a semantic unit (proper name, sentence, paragraph,
emphasis, etc). When we researched this stuff at AIRMICS, this could add 8-12% to the time to maintain code in large systems. Your eyes twitch! 
You really need to get your act together with a good text editor/ pretty printer tools. Get a copy of my SQL Programming Style and adapt it to those tools. 
>> The result is bonded to ASP.net grid view control. <<
We are the SQL guys; we do not are about the presentation layers :) 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • ** Is it possible to give select command from multiple tables in JDBC

    Hi Friends,
    Is it possible to give the select command to select data from multiple tables directly in the 'Query SQL statement' in JDBC sender communication channel ? (Instead of Stored Procedure)
    Thanking you.
    Kind Regards,
    Jeg P.

    Hi,
    here is a sample:
    Table #1
    Header
    Name EmpId Status
    Jai 5601 0
    Karthik 5579 0
    Table #2
    Name Contactnumber
    Jai 9894268913
    Jai 04312432431
    Karthik 98984110335
    Karthik 04222643993
    select Header.Name, Header.EmpId, Item.Contactnumber from Header,Item where Header.Name = (select min(Header.Name) from Header where Header.Status = 0) and Header.Name = Item.Name
    Regards Mario

  • Deleting Multiple Rows From Multiple Tables As an APEX Process

    Hi There,
    I'm interesting in hearing best practice approaches for deleting multiple rows from multiple tables from a single button click in an APEX application. I'm using 3.0.1.008
    On my APEX page I have a Select list displaying all the Payments made and a user can view individual payments by selecting a Payment from the Select List (individual items are displayed below using Text Field (Disabled, saves state) items with a source of Database Column).
    A Payment is to be deleted by selecting a custom image (Delete Payments Button) displayed in a Vertical Images List on the same page. The Target is set as the same page and I gave the Request a name of DELETEPAY.
    What I tried to implement was creating a Conditional Process On Submit - After Computations and Validations that has a source of a PL/SQL anonymous block as follows:
    BEGIN
    UPDATE tblDebitNotes d
    SET d.Paid = 0
    WHERE 1=1
    AND d.DebitNoteID = :P7_DEBITNOTEID;
    INSERT INTO tblDeletedPayments
    ( PaymentID,
    DebitNoteID,
    Amount,
    Date_A,
    SupplierRef,
    Description
    VALUES
    ( :P7_PAYMENTID,
    :P7_DEBITNOTEID,
    :P7_PAID,
    SYSDATE,
    :P7_SUPPLIERREF,
    :P7_DESCRIPTION
    DELETE FROM tblPayments
    WHERE 1=1
    AND PaymentID = :P7_PAYMENTID;
    END;
    The Condition Type used was Request = Expression 1 where Expression 1 had a value of DELETEPAY
    However this process is not doing anything!! Any insights greatly appreciated.
    Many thanks,
    Gary.

    ...the "button" is using a page level Target,...
    I'm not sure what that means. If the target is specified in the definition of a list item, then clicking on the image will simply redirect to that URL. You must cause the page to be submitted instead, perhaps by making the URL a reference to the javaScript doSubmit function that is part of the standard library shipped with Application Express. Take a look at a Standard Tab on a sample application and see how it submits the page using doSubmit() and emulate that.
    Scott

  • How to save the  selected rows from Advance table into database

    Hi
    I have requirement like..
    In custom page , Manager Search the Candidates and selects the candidate ROWS from advance table.
    The reqt is how to save the selected multiple rows into the database.

    hi Reetesh,
    In Custom page
    Supoose the Recruiter Search is for Position Finance Mangager , it retrieves 100 rows , out of which Recruiter select 10 rows .
    So in Such scenario how to save this 10 rows against Recruiter
    , i mean , Is i need to create custom table, to save Recruiter , these selected 10 rows.
    I hope u understand my question

  • Delete operation is not working to delete selected row from ADF table

    Hi All,
    We are working on jdev 11.1.1.5.3. We have one ADF table as shown below. My requirement is to delete a selected row from table, but it is deleting the first row only.
    <af:table value="#{bindings.EventCalendarVO.collectionModel}" var="row"
    rows="#{bindings.EventCalendarVO.rangeSize}"
    emptyText="#{bindings.EventCalendarVO.viewable ? applcoreBundle.TABLE_EMPTY_TEXT_NO_ROWS_YET : applcoreBundle.TABLE_EMPTY_TEXT_ACCESS_DENIED}"
    fetchSize="#{bindings.EventCalendarVO.rangeSize}"
    rowBandingInterval="0"
    selectedRowKeys="#{bindings.EventCalendarVO.collectionModel.selectedRow}"
    selectionListener="#{bindings.EventCalendarVO.collectionModel.makeCurrent}"
    rowSelection="single" id="t2" partialTriggers="::ctb1 ::ctb3"
    >
    To perform delete operation i have one delete button.
    <af:commandToolbarButton
    text="Delete"
    disabled="#{!bindings.Delete.enabled}"
    id="ctb3" accessKey="d"
    actionListener="#{AddNewEventBean. *deleteCurrentRow* }"/>
    As normal delete operation is not working i am using programatic approach from bean method. This approach works with jdev 11.1.1.5.0 but fails on ver 11.1.1.5.3
    public void deleteCurrentRow (ActionEvent actionEvent) *{*               DCBindingContainer bindings =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding dcItteratorBindings =
    bindings.findIteratorBinding("EventCalendarVOIterator");
    // Get an object representing the table and what may be selected within it
    ViewObject eventCalVO = dcItteratorBindings.getViewObject();
    // Remove selected row
    eventCalVO.removeCurrentRow();
    it is removing first row from table still. Main problem is not giving the selected row as current row. Any one point out where is the mistake?
    We have tried the below code as well in deleteCurrentRow() method
    RowKeySet rowKeySet = (RowKeySet)this.getT1().getSelectedRowKeys();
    CollectionModel cm = (CollectionModel)this.getT1().ggetValue();
    for (Object facesTreeRowKey : rowKeySet) {
    cm.setRowKey(facesTreeRowKey);
    JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)cm.getRowData();
    rowData.getRow().remove();
    The same behavior still.
    Thanks in advance.
    Rechin
    Edited by: 900997 on Mar 7, 2012 3:56 AM
    Edited by: 900997 on Mar 7, 2012 4:01 AM
    Edited by: 900997 on Mar 7, 2012 4:03 AM

    JDev 11.1.1.5.3 sounds like you are using oracle apps as this not a normal jdev version.
    as it works in 11.1.1.5.0 you probably hit a bug which you should file with support.oracle.com...
    Somehow you get the first row instead of the current row (i guess). You should debug your code and make sure you get the current selected row in your bean code and not the first row.
    This might be a problem with the bean scope too. Do you have the button (or table) inside a region? Wich scope does the bean have?
    Anyway you can try to remove the iterator row you get
    public void deleteCurrentRow (ActionEvent actionEvent) { DCBindingContainer bindings =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding dcItteratorBindings =
    bindings.findIteratorBinding("EventCalendarVOIterator");
    dcItteratorBindings.removeCurrentRow();Timo

  • Need sample code to get handle of Selected rows from ADF Table

    Hi,
    I am new to ADF. I have an ADF table based on VO object.On some button action,I need to get handle of selected rows in application module.
    If anybody is having sample code to do this then please share with me.
    Thanks,
    ashok

    wow now link http://blogs.oracle.com/smuenchadf/examples/#134 is working.thanks a lot.
    also the link http://baigsorcl.blogspot.com/2010/06/deleting-multi-selected-rows-from-adf.html is very useful. Thanks a lot for Sameh Nassar too.He made it clear that in 11g Select column is not available for a ADF table and provided a solution to get Select column.
    Thanks,
    ashok

  • Stored procedure to insert into multiple tables in sql server 2012, using id col from one table to insert into the other 2

    Hi all,
    Apologies if any of the following sounds at all silly but I am fairly new to this so here goes...
    I have 3 tables that require data insertion at the same time. The first table is the customers table, I then want to take the automatically generated custid from that table and inser it into 2 other tables along with some other data
    Here's what I have so far which does not work:
    CREATE PROCEDURE CustomerDetails.bnc_insNewRegistration @CustId int,
    @CompanyName varchar(100),
    @FirstName varchar(50),
    @LastName varchar(50),
    @Email nvarchar(254),
    @HouseStreet varchar(100),
    @Town smallint,
    @County tinyint,
    @Postcode char(8),
    @Password nvarchar(20)
    AS
    BEGIN
    begin tran
    insert into CustomerDetails.Customers
    (CompanyName, FirstName, LastName, EmailAddress)
    Values (@CompanyName, @FirstName, @LastName, @Email)
    set @CustId = (select CustId from inserted)
    insert into CustomerDetails.Address
    (CustomerId, HouseNoAndStreet, Town, County, PostCode)
    values (@CustId, @HouseStreet, @Town, @County, @Postcode)
    insert into CustomerDetails.MembershipDetails
    (CustomerId, UserName, Password)
    values (@CustId, @Email, @Password)
    commit tran
    END
    GO
    If anyone could help with this I would very much appreciate it as I am currently building an online store, if there's no registration there's no customers.
    So to whom ever is able to help, I thank you whole heartedly :)

    I hope by now it is apparent that statements like "doesn't work" are not particularly helpful. The prior posts have already identified your first problem.  But there are others.  First, you have declared @CustID as an argument for your
    procedure - but it is obvious that you do not expect a useful value to be supplied when the procedure is executed.  Perhaps it should be declared as an output argument so that the caller of the procedure can know the PK value of the newly inserted customer
    - otherwise, replace it with a local variable since it serves no purpose as an input argument.
    Next, you are storing email twice.  Duplication of data contradicts relational theory and will only cause future problems. 
    Next, I get the sense that your "customer" can be a person or a company.  You may find that using the same table for both is not the best approach.  I hope you have constraints to prevent a company from having a first and last name (and
    vice versa).
    Next, your error checking is inadequate.  We can only hope that you have the appropriate constraints to prevent duplicates.  You should expect failures to occur, from basic data errors (duplicates, null values, inconsistent values) to system issues
    (out of space).  I'll leave you with Erland's discussion for more detail:
    erland - error handling.
    Lastly, you should reconsider the datatypes you are using for the various bits of information.  Presumably town and county are foreign keys to related tables, which is why they are numeric.  Be careful you don't paint yourself into a corner with
    such small datatypes.  One can also debate the wisdom of using a separate tables for Town and County (and perhaps the decision to limit yourself to a particular geographic area with a particular civic hierarchy). Password seems a little short to me. 
    And if you are going to use nvarchar for some strings, you might as well use it for everything - especially names.  Also, everyone should be security conscious by now - passwords should be encrypted at the very least.
    And one last comment - you really should allow 2 address lines. Yes, two separate ones and not just one much larger one.

  • How to run a SQL server store procedure from Apex (oracle)?

    Our application needs to call a store procedure in the SQLserver database. The sotre procedure works fine in the SQL server side. However, when I tried to call the store procedure in TOAD as:
    exec my_store_procedure(para1, para2);
    I kept getting the error message:
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'my_store_procedure'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    I have searched online but couldn't find the solution. This is an emergency, so prompt reply is Highly Appreciated!
    Luc

    How is Oracle connecting to the SQL Server?
    With the Transparent Gateway or Generic Connectivity?
    I don't think that Generic Connectivity supports stored procedures.
    The documentation for Heterogeneous Connectivity is here:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14232/toc.htm
    You'd probably get better answers from the Heterogeneous Connectivity forum:
    Heterogeneous Connectivity

  • Count rows from multiple tables using SQL only

    Hi, I know this has probably been answered before, but I couldn't find the answer anywhere. Please help.
    I'd like count(*) [rows] for all tables in database using SQL only - no PL/SQL
    The result should be something like:
    Table RowCount
    DBA_TABLES 1000
    DBA_USERS 50
    etc.
    Thanks!

    offcource write this script:
    create or replace procedure count_tables (ip_schema VARCHAR2)
    is
    lv_owner VARCHAR2(100);
    lv_table_name VARCHAR2(100);
    lv_sql_statement VARCHAR2(2000);
    lv_count_table NUMBER;
    CURSOR c1 IS
    SELECT owner, table_name
    FROM all_tables
    WHERE owner = ip_schema
    ORDER BY table_name;
    begin
    dbms_output.put_line ('+--------------------------------------------------------------------+');
    dbms_output.put_line ('¦ | | ¦');
    dbms_output.put_line ('¦ Schema Name | Table Name | Number of Rows ¦');
    dbms_output.put_line ('¦ | | ¦');
    dbms_output.put_line ('¦------------------------------------------------------------------¦');
    OPEN c1;
    LOOP
    FETCH c1 INTO lv_owner , lv_table_name;
    EXIT WHEN c1%NOTFOUND;
    lv_sql_statement := 'SELECT count(*) FROM ' || lv_owner || '.' || lv_table_name;
    EXECUTE IMMEDIATE lv_sql_statement INTO lv_count_table;
    IF lv_count_table > 0 THEN
    dbms_output.put_line ('| '||rpad(lv_owner, 14, ' ')||'| '|| rpad(lv_table_name, 32, ' ')||'| '|| rpad(lv_count_table, 16, ' ')||' |');
    -- dbms_output.put_line ('|---------------|---------------------------------|------------------|');
    END IF;
    END LOOP;
    CLOSE c1;
    dbms_output.put_line ('+--------------------------------------------------------------------+');
    exception
    WHEN OTHERS THEN
    dbms_output.put_line ('owner: '||lv_owner||' - table: '||lv_table_name||' - '||sqlerrm);
    end count_tables;
    set serveroutput on size 1000000
    exec count_tables
    drop procedure count_tables;

  • JDBC adapter to SAP: select & join from multiple tables ???

    Hello,
    I have a task to get an aggregating information from two tables and send it into SAP.
    I use XI JDBC sender adapter to access to MSSQL DB.
    I know how to construct SQL quiery:
    (something like that)
    SELECT  table1.Date  SUM(table1.sum) from table1
    INNER JOIN table2
    ON table1.Number = table2.Number
    But I don't understand how to construct  Data Type for this complex select operator?
    How does it look like?
    Where to store and how to map the selected data?
    Please give me an example or an advice.
    Thank You.

    Hi,
    Use your structure like this.
    <StatementName4>
    <dbTableName action=”SELECT”>
    <table>realDbTableName</table>
    <access>
    <col1/>
    <col2/>
    <col3/>
    </access>
    <key1>
    <col2>val2old</col2>
    <col4>val4</col4>
    </key1>
    <key2>
    <col2>val2old2</col2>
    </key2>
    </dbTableName>
    </StatementName4>
    action=SELECT
    Statements with this action cause existing table values to be selected. Therefore, the statement corresponds to an SQL SELECT statement.
    The <access> block contains the column names to be selected, a <key> element contains the columns whose values must be identical with the specified value to get the new column values. The name of the <key> element is arbitrary. Column values within a <key> element are combined with a logical AND; different <key> elements are combined with a logical OR.
    A statement with the action SELECT must have exactly one <access> element. The number of <key> elements with arbitrary names is not restricted.
    The corresponding SQL statement for StatementName4 in the example above is as follows:
    SELECT col1,col2,col3 FROM dbTableName WHERE ((col2=’val2old’ AND col4=’val4’) OR (col2=’val2old2’))
    If there is no <key> element, or if there is a <key> element but it is empty, then no condition is specified and the entire table is to be selected. This may not be permitted by the configuration of the JDBC adapter for security reasons and will therefore result in an error during message processing and an appropriate error message.
    The response document contains the result of the action in XML format as follows:
    <row>
    <column1>value11</column1>
    <column2>value12</column2>
    </row>
    <row>
    <column1>valueN1</column1>
    <column2>valueN2</column2>
    </row>
    This will help you.
    regards
    Aashish Sinha
    PS : reward points if helpful

  • SQL Server 2014 - Delete duplicate rows in a table except one

    Hi all,
    I have a table that contains duplicate rows. Using grouping I can easily identify those rows.
    As of now, I count the grouped records and copy one of the group in a temporary table together with its count of elements. Than I loop over this table and delete N - 1 rows of each group from the original table. Unfortunately this is done with two cursors
    and WHILE loops.
    Is anybody out there who could give some hints how to handle deletion of duplicated rows leaving one in place using pure SQL? I tried a full delete of all elements of a group and then an INSERT of one row to recreate a row again. But this is not
    very elegant and close to using cursors.
    Regards Uwe

    Hi all,
    based on input below from Uri, I have developed a little more general solution for removal of duplicates. I did that, because I'm sure that for many beginners in SQL it is easier specialize a proposal by removing parts of it than adding new functionality.
    Here is my code.
    -- Remove duplicates from a table and document the deleted rows
    DECLARE @MyTable Table (Col1 int, Col2 int, Col3 int, Col4 int);
    DECLARE @OutTable Table (Col1 int, Col2 int, Col3 int, Col4 int);
    INSERT INTO @MyTable VALUES
    (1, 10, 100, 7),
    (2, 20, 200, 2),
    (2, 20, 200, 1),
    (3, 30, 300, 3),
    (1, 10, 200, 4),
    (1, 10, 100, 5),
    (1, 10, 100, 6);
    WITH cte (RN, Col1, Col2, Col3, Col4)
    AS (SELECT ROW_NUMBER() OVER (PARTITION BY Col1, Col2, Col3 ORDER BY (SELECT 0)) AS RN, Col1, Col2, Col3, Col4
    FROM @MyTable)
    DELETE FROM cte
    OUTPUT DELETED.Col1, DELETED.Col2, DELETED.Col3, DELETED.Col4
    INTO @OutTable (Col1, Col2, Col3, Col4)
    WHERE RN > 1;
    SELECT * FROM @OutTable;
    And this is the result:
    The MS 139444 article Satish mentioned is focussed on duplicate PKs removal. Thanks for the hint.
    Thanks to you all for your rapid response.
    Regards Uwe

  • How to fetch rows from multiple tables

    I have a page with items from 3 tables. I need to populate these items with values from the database. The page does not allow me to use multiple automated fetches. So instead I decided to use a pl/sql page process that runs a cursor to get my field values and the uses apex_util.set_session_state to set the field item values. IS there any isues with doing this? Is there a better way?

    These tables are not really related so I gues I will stick with the pl/sql to populate and then page process to insert/update/delete. Here is the code I'm using.
    Chris
    DECLARE
    CURSOR get_info IS
    select A.FK_STU_BASE, A.FK_CONTACT, A.FK_RELATION, A.PRIORITY, A.CAN_PICK_UP_STUDENT,
    A.GETS_STX, A.GETS_STG, A.GETS_STA, A.GETS_DIS, A.GETS_THX, A.GETS_MED,
    A.GETS_MAIL, A.NOTES as STUDENT_NOTES, A.USER_FLD1, A.USER_FLD2, A.USER_FLD3,
    A.USER_FLD4, A.USER_FLD5, A.LAST_UPDATE_DATE, A.LAST_UPDATE_USER,
    B.PK_ID as CONTACT_PK_ID, B.FIRST_NAME, B.LAST_NAME, B.MIDDLE_INIT, B.PREFIX,
    B.SUFFIX, B.FK_LANGUAGE, B.PHONE, B.PHONE_UNLISTED, B.PHONE_EXTENSION,
    B.PHONE_DESCRIPTION, B.EMERGENCY_PHONE, B.EMERGENCY_UNLISTED, B.EMERGENCY_EXTENSION,
    B.EMERGENCY_DESCRIPTION, B.CELL_PHONE, B.CELL_UNLISTED, B.CELL_EXTENSION,
    B.CELL_DESCRIPTION, B.CELL2_PHONE, B.CELL2_UNLISTED, B.CELL2_EXTENSION,
    B.CELL2_DESCRIPTION, B.WORK1_PHONE, B.WORK1_UNLISTED, B.WORK1_EXTENSION,
    B.WORK1_DESCRIPTION, B.WORK2_PHONE, B.WORK2_UNLISTED, B.WORK2_EXTENSION,
    B.WORK2_DESCRIPTION, B.FAX_PHONE, B.FAX_DESCRIPTION, B.EMAIL1, B.EMAIL2,
    B.NOTES as CONTACT_NOTES, B.FK_LODGING, B.FK_EDUCATION_LEVEL,
    C.PK_ID as LODGING_PK_ID, C.FK_ZIP, C.FK_DISTRICT, C.HOUSE_NO, C.LETTER,
    C.DIRECTION, C.STREET, C.STREET2, C.PLUS4, C.APT, C.FK_GRIDCODE,
    C.FK_MUNICIPALITY, C.OPTIONAL_INFO1, C.OPTIONAL_INFO2, C.OPTIONAL_INFO3,
    C.FK_DWELLING, C.OPTIONAL_ZIPCODE
    from contact_link A,
    contact B,
    lodging C
    where A.PK_ID = :P470_CONTACT_LINK_PK_ID and
    B.PK_ID (+) = A.FK_CONTACT and
    C.PK_ID (+) = B.FK_LODGING;
    BEGIN
    FOR x in get_info LOOP
    -- Set Contact Link Items
    APEX_UTIL.SET_SESSION_STATE('P470_FK_STU_BASE',X.FK_STU_BASE);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_CONTACT',X.FK_CONTACT);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_RELATION',X.FK_RELATION);
    APEX_UTIL.SET_SESSION_STATE('P470_PRIORITY',X.PRIORITY);
    APEX_UTIL.SET_SESSION_STATE('P470_CAN_PICK_UP_STUDENT',X.CAN_PICK_UP_STUDENT);
    APEX_UTIL.SET_SESSION_STATE('P470_GETS_STX',X.GETS_STX);
    APEX_UTIL.SET_SESSION_STATE('P470_GETS_STG',X.GETS_STG);
    APEX_UTIL.SET_SESSION_STATE('P470_GETS_STA',X.GETS_STA);
    APEX_UTIL.SET_SESSION_STATE('P470_GETS_DIS',X.GETS_DIS);
    APEX_UTIL.SET_SESSION_STATE('P470_GETS_THX',X.GETS_THX);
    APEX_UTIL.SET_SESSION_STATE('P470_GETS_MED',X.GETS_MED);
    APEX_UTIL.SET_SESSION_STATE('P470_GETS_MAIL',X.GETS_MAIL);
    APEX_UTIL.SET_SESSION_STATE('P470_STUDENT_NOTES',X.STUDENT_NOTES);
    APEX_UTIL.SET_SESSION_STATE('P470_USER_FLD1',X.USER_FLD1);
    APEX_UTIL.SET_SESSION_STATE('P470_USER_FLD2',X.USER_FLD2);
    APEX_UTIL.SET_SESSION_STATE('P470_USER_FLD3',X.USER_FLD3);
    APEX_UTIL.SET_SESSION_STATE('P470_USER_FLD4',X.USER_FLD4);
    APEX_UTIL.SET_SESSION_STATE('P470_USER_FLD5',X.USER_FLD5);
    APEX_UTIL.SET_SESSION_STATE('P470_LAST_UPDATE_DATE',X.LAST_UPDATE_DATE);
    APEX_UTIL.SET_SESSION_STATE('P470_LAST_UPDATE_USER',X.LAST_UPDATE_USER);
    --Set Contact Items
    APEX_UTIL.SET_SESSION_STATE('P470_CONTACT_PK_ID',X.CONTACT_PK_iD);
    APEX_UTIL.SET_SESSION_STATE('P470_FIRST_NAME',X.FIRST_NAME);
    APEX_UTIL.SET_SESSION_STATE('P470_LAST_NAME',X.LAST_NAME);
    APEX_UTIL.SET_SESSION_STATE('P470_MIDDLE_INIT',X.MIDDLE_INIT);
    APEX_UTIL.SET_SESSION_STATE('P470_PREFIX',X.PREFIX);
    APEX_UTIL.SET_SESSION_STATE('P470_SUFFIX',X.SUFFIX);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_LANGUAGE',X.FK_LANGUAGE);
    APEX_UTIL.SET_SESSION_STATE('P470_PHONE',X.PHONE);
    APEX_UTIL.SET_SESSION_STATE('P470_PHONE_UNLISTED',X.PHONE_UNLISTED);
    APEX_UTIL.SET_SESSION_STATE('P470_PHONE_EXTENSION',X.PHONE_EXTENSION);
    APEX_UTIL.SET_SESSION_STATE('P470_PHONE_DESCRIPTION',X.PHONE_DESCRIPTION);
    APEX_UTIL.SET_SESSION_STATE('P470_EMERGENCY_PHONE',X.EMERGENCY_PHONE);
    APEX_UTIL.SET_SESSION_STATE('P470_EMERGENCY_UNLISTED',X.EMERGENCY_UNLISTED);
    APEX_UTIL.SET_SESSION_STATE('P470_EMERGENCY_EXTENSION',X.EMERGENCY_EXTENSION);
    APEX_UTIL.SET_SESSION_STATE('P470_EMERGENCY_DESCRIPTION',X.EMERGENCY_DESCRIPTION);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL_PHONE',X.CELL_PHONE);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL_UNLISTED',X.CELL_UNLISTED);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL_EXTENSION',X.CELL_EXTENSION);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL_DESCRIPTION',X.CELL_DESCRIPTION);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL2_PHONE',X.CELL2_PHONE);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL2_UNLISTED',X.CELL2_UNLISTED);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL2_EXTENSION',X.CELL2_EXTENSION);
    APEX_UTIL.SET_SESSION_STATE('P470_CELL2_DESCRIPTION',X.CELL2_DESCRIPTION);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK1_PHONE',X.WORK1_PHONE);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK1_UNLISTED',X.WORK1_UNLISTED);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK1_EXTENSION',X.WORK1_EXTENSION);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK1_DESCRIPTION',X.WORK1_DESCRIPTION);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK2_PHONE',X.WORK2_PHONE);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK2_UNLISTED',X.WORK2_UNLISTED);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK2_EXTENSION',X.WORK2_EXTENSION);
    APEX_UTIL.SET_SESSION_STATE('P470_WORK2_DESCRIPTION',X.WORK2_DESCRIPTION);
    APEX_UTIL.SET_SESSION_STATE('P470_FAX_PHONE',X.FAX_PHONE);
    APEX_UTIL.SET_SESSION_STATE('P470_FAX_DESCRIPTION',X.FAX_DESCRIPTION);
    APEX_UTIL.SET_SESSION_STATE('P470_EMAIL1',X.EMAIL1);
    APEX_UTIL.SET_SESSION_STATE('P470_EMAIL2',X.EMAIL2);
    APEX_UTIL.SET_SESSION_STATE('P470_CONTACT_NOTES',X.CONTACT_NOTES);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_LODGING',X.FK_LODGING);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_EDUCATION_LEVEL',X.FK_EDUCATION_LEVEL);
    --Set Lodging Items
    APEX_UTIL.SET_SESSION_STATE('P470_LODGING_PK_ID',X.LODGING_PK_ID);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_ZIP',X.FK_ZIP);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_DISTRICT',X.FK_DISTRICT);
    APEX_UTIL.SET_SESSION_STATE('P470_HOUSE_NO',X.HOUSE_NO);
    APEX_UTIL.SET_SESSION_STATE('P470_LETTER',X.LETTER);
    APEX_UTIL.SET_SESSION_STATE('P470_DIRECTION',X.DIRECTION);
    APEX_UTIL.SET_SESSION_STATE('P470_STREET',X.STREET);
    APEX_UTIL.SET_SESSION_STATE('P470_STREET2',X.STREET2);
    APEX_UTIL.SET_SESSION_STATE('P470_PLUS4',X.PLUS4);
    APEX_UTIL.SET_SESSION_STATE('P470_APT',X.APT);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_GRIDCODE',X.FK_GRIDCODE);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_MUNICIPALITY',X.FK_MUNICIPALITY);
    APEX_UTIL.SET_SESSION_STATE('P470_OPTIONAL_INFO1',X.OPTIONAL_INFO1);
    APEX_UTIL.SET_SESSION_STATE('P470_OPTIONAL_INFO2',X.OPTIONAL_INFO2);
    APEX_UTIL.SET_SESSION_STATE('P470_OPTIONAL_INFO3',X.OPTIONAL_INFO3);
    APEX_UTIL.SET_SESSION_STATE('P470_FK_DWELLING',X.FK_DWELLING);
    APEX_UTIL.SET_SESSION_STATE('P470_OPTIONAL_ZIPCODE',X.OPTIONAL_ZIPCODE);
    END LOOP;
    END;

  • Get selected row from af:table in backing bean

    Hi Experts,
    I have an af:table and i have seelctBoolean check box in that. If the user select 'x' nos of check boxes i want to display the row data of those selected rows. Can somebody help me in getting the selected row data in backing bean?
    I am using adf faces and backing bean.
    JSF Code:
    <af:table value="#{demo.partyList}" var="row"
    rowBandingInterval="0" binding="#{demo.t1}" id="t21"
    rowSelection="multiple">
    <af:column>
    <af:selectBooleanCheckbox text="#{row.person_first_name}"
    label="Label 1" id="sbc1"
    />
    </af:column>
    <af:column>
    <af:inputText value="#{row.emirate}"/>
    </af:column>
    </af:table>
    <af:commandButton action="#{demo.print}" text="Print"/>
    BB Code:
    public void print(){
    // what code to write here
    }

    This is the code
    JSF ::
    <af:table value="#{createOpportunity.dataList}" var="row"
    rowBandingInterval="0" binding="#{demo.t1}" id="t21">
    <af:column headerText="Model">
    <af:selectBooleanCheckbox text="#{row.modelRange}"
    label="Label 1" id="sbc1" value="#{row.selected}"/>
    </af:column>
    <af:column headerText="Description">
    <af:outputText value="#{row.description}"/>
    </af:column>
    <af:column>
    <af:inputText value="#{row.quantity}"/>
    </af:column>
    </af:table>
    <af:commandButton action="#{createOpportunity.print}" text="Print"/>
    Backing bean Code::
    public void print () {
    selectedDataList = new ArrayList<ModelDescription>();
    for (ModelDescription dataItem : dataList) {
    if (dataItem.isSelected()) {
    System.out.println(dataItem.getQuantity());
    selectedDataList.add(dataItem);
    // dataItem.setSelected(false); // Reset.
    Clicking on the print button shows "We have 0 rows selected"
    Thnks for ur replies guys ..
    Edited by: Wannabe Java Guru on Mar 9, 2011 1:43 AM

  • Selecting rows across multiple tables (SSCCE provided)

    Greetings,
    I have a program that has 3 tables. When the user selects a row on one table, I want the corresponding rows in the other tables to be selected also. A corresponding row is defined (in this case) as a row whose column 1 value is the same. Column 1, in this case, is a company name, and the tables reference yearly info for those companies. So, if a user selects company #34, I would like it to select company #34 across the other two tables, also.
    I have established list selection listeners for each table that changes the selection for the other two tables.
    This code, however, doesn't work. two things are broken: 1) the cross-selection only works if the selection is moving up the table, but not down the table. 2) the scrrollRectToVisible on the viewport isn't working. What am I doing wrong? Thanks in advance.
    import java.awt.Rectangle;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    * @author Ryan
    public class TableSelection {
        public static void main(String[] args){
            // Init data model data.
            Object[][] data = new Object[100][5];
            for(int i = 0; i < data.length; i++){
                data[0] = "Company # " + i;
    for(int j = 1; j < data[i].length; j++){
    data[i][j] = "" + i + ", " + j;
    // Init headers.
    String[] headers = {"Col 1" , "Col 2", "Col 3", "Col 4", "Col 5"};
    // All 3 data models are the same here, in my app however, they aren't.
    DefaultTableModel model1 = new DefaultTableModel(data, headers);
    DefaultTableModel model2 = new DefaultTableModel(data, headers);
    DefaultTableModel model3 = new DefaultTableModel(data, headers);
    // Init Tables. Tables and ScrollPanes are delcared as final to enable access from within ListSelectionEvent
    // Table 1
    final JTable jTable1 = new JTable(model1);
    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final JScrollPane sp1 = new JScrollPane();
    sp1.setViewportView(jTable1);
    // Table 2
    final JTable jTable2 = new JTable(model2);
    jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final JScrollPane sp2 = new JScrollPane();
    sp2.setViewportView(jTable2);
    // Table 3
    final JTable jTable3 = new JTable(model3);
    jTable3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final JScrollPane sp3 = new JScrollPane();
    sp3.setViewportView(jTable3);
    // Add scrollpanes to panel.
    JPanel panel1 = new JPanel();
    panel1.add(sp1);
    panel1.add(sp2);
    panel1.add(sp3);
    // Add Panel to frame.
    JFrame frame = new JFrame("tableSelection");
    frame.add(panel1);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    // List Selection Listeners
    jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    // Get the first cell in the selected row, I call it "row key".
    String rowKey = jTable1.getValueAt(e.getFirstIndex(), 0).toString();
    for(int i = 0; i < jTable2.getRowCount(); i++){
    if(jTable2.getValueAt(i, 0).equals(rowKey)){
    jTable2.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable2.getCellRect(i, 0, true);
    sp2.getViewport().scrollRectToVisible(rect);
    break;
    for(int i = 0; i < jTable3.getRowCount(); i++){
    if(jTable3.getValueAt(i, 0).equals(rowKey)){
    jTable3.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable3.getCellRect(i, 0, true);
    sp3.getViewport().scrollRectToVisible(rect);
    break;
    jTable2.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    // Get the first cell in the selected row, I call it "row key".
    String rowKey = jTable2.getValueAt(e.getFirstIndex(), 0).toString();
    for(int i = 0; i < jTable1.getRowCount(); i++){
    if(jTable1.getValueAt(i, 0).equals(rowKey)){
    jTable1.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable1.getCellRect(i, 0, true);
    sp1.getViewport().scrollRectToVisible(rect);
    break;
    for(int i = 0; i < jTable3.getRowCount(); i++){
    if(jTable3.getValueAt(i, 0).equals(rowKey)){
    jTable3.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable3.getCellRect(i, 0, true);
    sp3.getViewport().scrollRectToVisible(rect);
    break;
    jTable3.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    // Get the first cell in the selected row, I call it "row key".
    String rowKey = jTable3.getValueAt(e.getFirstIndex(), 0).toString();
    for(int i = 0; i < jTable1.getRowCount(); i++){
    if(jTable1.getValueAt(i, 0).equals(rowKey)){
    jTable1.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable1.getCellRect(i, 0, true);
    sp1.getViewport().scrollRectToVisible(rect);
    break;
    for(int i = 0; i < jTable2.getRowCount(); i++){
    if(jTable2.getValueAt(i, 0).equals(rowKey)){
    jTable2.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable2.getCellRect(i, 0, true);
    sp2.getViewport().scrollRectToVisible(rect);
    break;

    New code:
    import java.awt.Rectangle;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    * @author Ryan
    public class TableSelection {
        public static void main(String[] args){
            // Init data model data.
            Object[][] data1 = new Object[100][5];
            Object[][] data2 = new Object[50][5];
            Object[][] data3 = new Object[50][5];
            for(int i = 0; i < data1.length; i++){
                data1[0] = "Company # " + (i+1);
    for(int j = 1; j < data1[i].length; j++){
    data1[i][j] = "" + (i+1) + ", " + j;
    for(int i = 0; i < data2.length; i++){
    data2[i][0] = "Company # " + ((i * 2) + 1);
    for(int j = 1; j < data2[i].length; j++){
    data2[i][j] = "" + ((i * 2) + 1) + ", " + j;
    for(int i = 0; i < data3.length; i++){
    data3[i][0] = "Company # " + (i * 2);
    for(int j = 1; j < data3[i].length; j++){
    data3[i][j] = "" + (i * 2) + ", " + j;
    // Init headers.
    String[] headers = {"Col 1" , "Col 2", "Col 3", "Col 4", "Col 5"};
    // All 3 data models are the same here, in my app however, they aren't.
    DefaultTableModel model1 = new DefaultTableModel(data1, headers);
    DefaultTableModel model2 = new DefaultTableModel(data2, headers);
    DefaultTableModel model3 = new DefaultTableModel(data3, headers);
    // Init Tables. Tables and ScrollPanes are delcared as final to enable access from within ListSelectionEvent
    // Table 1
    final JTable jTable1 = new JTable(model1);
    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final JScrollPane sp1 = new JScrollPane();
    sp1.setViewportView(jTable1);
    // Table 2
    final JTable jTable2 = new JTable(model2);
    jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final JScrollPane sp2 = new JScrollPane();
    sp2.setViewportView(jTable2);
    // Table 3
    final JTable jTable3 = new JTable(model3);
    jTable3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final JScrollPane sp3 = new JScrollPane();
    sp3.setViewportView(jTable3);
    // Add scrollpanes to panel.
    JPanel panel1 = new JPanel();
    panel1.add(sp1);
    panel1.add(sp2);
    panel1.add(sp3);
    // Add Panel to frame.
    JFrame frame = new JFrame("tableSelection");
    frame.add(panel1);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    // List Selection Listeners
    jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    // Get the first cell in the selected row, I call it "row key".
    String rowKey = jTable1.getValueAt(e.getFirstIndex(), 0).toString();
    for(int i = 0; i < jTable2.getRowCount(); i++){
    if(jTable2.getValueAt(i, 0).equals(rowKey)){
    jTable2.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable2.getCellRect(i, 0, true);
    sp2.getViewport().scrollRectToVisible(rect);
    break;
    if(i == jTable2.getRowCount() - 1)
    jTable2.clearSelection();
    for(int i = 0; i < jTable3.getRowCount(); i++){
    if(jTable3.getValueAt(i, 0).equals(rowKey)){
    jTable3.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable3.getCellRect(i, 0, true);
    sp3.getViewport().scrollRectToVisible(rect);
    break;
    if(i == jTable3.getRowCount() - 1)
    jTable3.clearSelection();
    jTable2.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    // Get the first cell in the selected row, I call it "row key".
    String rowKey = jTable2.getValueAt(e.getFirstIndex(), 0).toString();
    for(int i = 0; i < jTable1.getRowCount(); i++){
    if(jTable1.getValueAt(i, 0).equals(rowKey)){
    jTable1.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable1.getCellRect(i, 0, true);
    sp1.getViewport().scrollRectToVisible(rect);
    break;
    if(i == jTable1.getRowCount() - 1)
    jTable1.clearSelection();
    for(int i = 0; i < jTable3.getRowCount(); i++){
    if(jTable3.getValueAt(i, 0).equals(rowKey)){
    jTable3.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable3.getCellRect(i, 0, true);
    sp3.getViewport().scrollRectToVisible(rect);
    break;
    if(i == jTable3.getRowCount() - 1)
    jTable3.clearSelection();
    jTable3.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    // Get the first cell in the selected row, I call it "row key".
    String rowKey = jTable3.getValueAt(e.getFirstIndex(), 0).toString();
    for(int i = 0; i < jTable1.getRowCount(); i++){
    if(jTable1.getValueAt(i, 0).equals(rowKey)){
    jTable1.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable1.getCellRect(i, 0, true);
    sp1.getViewport().scrollRectToVisible(rect);
    break;
    if(i == jTable1.getRowCount() - 1)
    jTable1.clearSelection();
    for(int i = 0; i < jTable2.getRowCount(); i++){
    if(jTable2.getValueAt(i, 0).equals(rowKey)){
    jTable2.getSelectionModel().setSelectionInterval(i, i);
    Rectangle rect = jTable2.getCellRect(i, 0, true);
    sp2.getViewport().scrollRectToVisible(rect);
    break;
    if(i == jTable2.getRowCount() - 1)
    jTable2.clearSelection();

  • Select rows from the table which don't exist in another table

    Hi, in this relatively simple task I have some problem. I need to get the records from the T1 which don't exist in T2, based on some criteria.
    here is my query:
    select a.ordernum, sum(totchg), b.tracknum, rownum from T1 a, T2 b where 1=1 and a.ordernum not in( select ordernum from T2 ) and entrydate between to_date('06/23/2007','MM/dd/yyyy') and to_date('06/30/2007','MM/dd/yyyy') group by a.ordernum, b.tracknum, rownum
    it suppose to return me "TRACKNUM" empty, however it's being returned populated.
    I also tried :
    select a.ordernum, sum(totchg),b.tracknum, rownum from T1 a,
    T2 b where[b] not exists( select '1' from T2 where a.ordernum = b.ordernum )
    and entrydate between to_date('06/23/2007','MM/dd/yyyy') and to_date('06/30/2007','MM/dd/yyyy') group by a.ordernum, b.tracknum, rownum
    the results are the same.
    please advise.

    You are trying to get a returned value field from T2 when you just said that the
    records returned from Only T1 are not found in T2, therefore no T2 record to return.
    You only get T1 records where the Ordernum key is not found in T2.
    select ordernum, tracknum, rownum, sum(totchg)
    from T1
    where ordernum not in( select ordernum from T2 )
    and (entrydate between to_date('06/23/2007','MM/dd/yyyy') and
    to_date('06/30/2007','MM/dd/yyyy') )
    group by ordernum, tracknum, rownum

Maybe you are looking for