How to return mismatched rows from two tables?

I have created two tables in the same database as below which gives the row
count of tables across all databases before and after an DB restore
operation.
create table before_restore(db_name varchar(100),table_name
varchar(1000),row_count int) insert into before_restore exec sp_msforeachdb 'USE
[?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o
inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by
o.name'
create table after_restore(db_name varchar(100),table_name
varchar(1000),row_count int) insert into after_restore exec sp_msforeachdb 'USE
[?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o
inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by
o.name'
I want to compare these two tables and it should only return me rows that
have changed after the restore operation is complete.
Eg:
Table xyz has rowcount of 100 before restore and the restore was not proper
and after restore count is 50. So it should return me the result set as
below;
Db_name    Table_Name  row_count_before_restore    row_count_after_restore
abc                   xyz                       100                              
   50
Thanks!!!

Something like below perhaps? Btw, I recommend using catalog view and dynamic management views instead of the old system tables (now called compatibility views)...
SELECT
COALESCE(a.db_name, b.db_name) AS db_name
,COALESCE(a.table_name, b.table_name) AS table_name
,a.row_count AS row_count_before_restore
,b.row_count AS row_count_after_restore
FROM before_restore AS b FULL OUTER JOIN after_restore AS a ON b.db_name = a.db_name AND b.table_name = a.table_name
WHERE b.row_count <> a.row_count OR b.db_name IS NULL OR a.db_name IS NULL
Tibor Karaszi, SQL Server MVP |
web | blog

Similar Messages

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • How NOT to restrict no of rows from two tables

    I have two identical tables Invoice and Payment. The only difference is Invoice_id,Invoice_Amt and Payment_id,Payment_Amt columns that shows different ids and amounts. The bank_ids, names, account_types are same. Invoice table has 3 rows and Payment has 2. Simply meaning that there were 3 invoices generated but the bank received 2 payments. I want to show Invoice_Amt and Payment_Amt using sql query. But its giving me total 6 rows. Whereas, I want 3 from Invoice and 2 rows from Payment table to show side-by-side.
    CREATE TABLE invoice
    ( invoice_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    invoice_amount NUMBER);
    ----Invoice table has 3 rows showing 3 Invoice Amts
    CREATE TABLE payment
    ( payment_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    payment_amount NUMBER);
    ----Payment table has 2 rows showing 2 Payments
    After executing this sql statement below, I get 6 rows:
    select inv.invoice_amount,pymt.payment_amount from invoice inv,payment pymt where inv.bank_id=pymt.bank_id;
    How can I show 3 rows for Invoice and 2 for Payment..?
    Thank you.

    Hi,
    So you want
    the 1st invoice to appear side-by-side with the 1st payment,
    the 2nd invoice to appear side-by-side with the 2nd payment,
    the nth invoice to appear side-by-side with the nth payment.
    But, if there are an uneqaul numner of payments and invoices, all the payments and all the invoices must still be shown, alone on a row if necessary.
    That sounds like a job for FULL OUTER JOIN.
    Use the analytic ROW_NUMBER fucntion to determine which is the 1st, 2nd, ..., nth row in each table, for each bank.
    WITH     invoice_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      invoice_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          invoice_id
                           )         AS r_num
         FROM    invoice
    ,     payment_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      payment_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          payment_id
                           )         AS r_num
         FROM    payment
    SELECT       NVL (i.bank_id,   p.bank_id)          AS bank_id
    ,       NVL (i.bank_name, p.bank_name)     AS bank_name
    ,       i.invoice_amount
    ,       p.payment_amount
    FROM          invoice_plus_r_num     i
    FULL OUTER JOIN     payment_plus_r_num     p  ON   i.bank_id     = p.bank_id
                                        AND     i.bank_name     = p.bank_name
                                AND     i.r_num          = p.r_num
    ORDER BY  bank_id     -- you can use column aliases here
    ,       bank_name
    ,       NVL (i.r_num, p.r_num)
    ;You mentioned something about accounts, but didn't include that in the CREATE TABLE statements. You'll probably want to add that wherever I used bank_id and bank_name, above.
    Are invoce and payment actually views, rather than tables? If not, you should have a separate bank table, and only include the bank_id in the other tables.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Feb 3, 2011 12:32 PM

  • Select unique rows from two tables...

    Hi,
    I have two tables, replies1 and replies2.
    SQL> desc replies
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    FILESIZE NUMBER
    AS_NUM VARCHAR2(6)
    SQL> desc replies2
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    AS_NUM VARCHAR2(6)
    Both of the tables have no primary keys, but I have indixes on (urn, addrss) combination on both....
    I am trying to select the unique rows with (urn, address) from replies2, and then find the matching size from replies...
    I am using the following query:
    select distinct replies2.urn, replies2.address, replies.filesize from replies2, replies where replies2.AS_NUM like 'XYZ' and replies.urn = replies2.urn;
    I cannot figure out why it won't work. the way I understand it is that, distinct will give all distinct combination of all column names that follow, which is what I want...
    I know it is wrong, because the query:
    select count(*) from replies2 where AS_NUM like 'XYZ' returns less number of rows than the above query.
    Any help would be greatly appreciated.
    Thank you
    Oz.

    Thanks a lot Mohan for your reply.
    urn is not a unique key. Several rows could have the same (urn, address) pair in both tables. What I want is retrieve all (urn, address) rows from one table, and find the size from the other table to make a (urn, address, size). I want all unique combinations of (urn, address) to appear in the output.
    AS_NUM is an empty column in replies... It would've been a lot easier if it wasn't, since then I'll just say: select distinct urn, address, filesize from replies where AS_NUM like 'XYZ';
    I will try your query though and let u know how it goes. It takes quite a while to run since my tables are huge.

  • How to return course  data  from different tables from a procedure

    I have a procedure which must return information from two tables:
    The sturcture of tables is as below:
    Table 1:
    id,
    name,
    property,
    type
    Table 2:
    id1
    id2 ,
    property.
    id1 of table2 refers to id attribute of table1. ie id is the foreign key for table2.
    the tables are defined such that for corresponding to each id in table1 there would
    be two or more rows in table2.
    Now in the procedure given the id, i need to retrieve information from table1 and also all the rows in table2 which refers to id2.I want to return a cursor.How can i do this.
    eg:
    if table 1 has an entry with id 2
    and table 2 has three entries with id1 referring to id(i.e id1=2)..I need to return the table1 entry with id=2 and three entires from table2 with id1=2.
    If cursors are not appropriate, what other alternative methods can be used.
    Any suggestions would be of great help.

    thanks for the reply,
    The result set would be returned to the client .....which would do further processing.The client does not even know that the data is organized in two tables..Therefore given an id, client would expect to have all the information...i.e the info from table 1 and info from table 2 where the relation ship between id and other ids are stored.
    i.e say client has id=6.This id has property,name,etc stored in table1.
    This id can further be related to any number other of ids.It can be related 2,5,100,or may be even 10000s of other ids.This mapping between the original id and other ids..are stored in table2.
    So given the id by the client , i would want to return property of the ids itself along with all the ids that it is related to .
    I want to achieve this.....

  • How to delete multiple rows from ADF table

    How to delete multiple rows from ADF table

    Hi,
    best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
    Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
    Frank

  • How to get multiple rows from database table?

    hello !
    I need to get multiple rows from a OLEDB database table and display them on a table object.
    I did "Wrap in subfrom" on the table,  set  subform of the table to "flowed", and checked "Repeat row for each data item" of Row1 of the table.
    But I can get only one row on the table object.
    I need your help.
    Thanks

    Hi,
    best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
    Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
    Frank

  • How do you Select data from two tables with similar data amd merge the output together.

    I have two Tables containing Sales Data. I want to read the Table a sort by date and accumulate dollars by order date. Then I want to read the second table and accumulate these dollar amounts by date and then merge the records together so that I gave 1 row
    with amounts for type A and amounts for type b.
    Here are the tables I am looking at.
    Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
              ,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
              ,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
              ,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
              ,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
              ,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
              ,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
              ,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
    from [PRODUCTION].dbo.Job As J
    union all
    Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
              ,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
              ,Sum(Case when Sales_Code = '5-Day'     then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
              ,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
              ,Sum(Case when Sales_Code = ''          then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
              ,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
              ,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
              ,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
    from [PRODUCTION].dbo.SO_Detail As SD
    Inner Join [PRODUCTION].dbo.SO_Header As SH
        on SD.Sales_Order = SH.Sales_Order
    Group by J.Order_Date
    Order by J.Order_Date Desc
    Looking for output like
    Order Date   Job Comm   Job AUto   Job Fixed    SO Comm  SO AUto  SO Fixed
    Mar-11-2014    100.00     250.00       50.00     200.00   300.00    400.00
    Mar-10-2014    500.00     340.00        0.00     110.00   400.00    500.00
    Mar-09-2014    600.00     333.00       56.00     210.00   500.00    300.00
    Thanks for your help
    SWProduction

    Seeing the output it looks like what you need is this
    select COALESCE(p.[Order Date],q.[Order Date]) AS [Order Date],
    COALESCE([Job Comm],0) AS [Job Comm],
    COALESCE([Job AUto],0) AS [Job AUto],COALESCE([Job Fixed],0) AS [Job Fixed],COALESCE([SO Comm],0) AS [SO Comm],COALESCE([SO AUto],0) AS [SO AUto],COALESCE([SO Fixed],0) AS [SO Fixed]
    from
    Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
    ,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
    ,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
    ,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
    ,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
    ,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
    ,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
    ,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
    from [PRODUCTION].dbo.Job As J
    )p
    full join
    Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
    ,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
    ,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
    ,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
    ,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
    ,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
    ,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
    ,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
    from [PRODUCTION].dbo.SO_Detail As SD
    Inner Join [PRODUCTION].dbo.SO_Header As SH
    on SD.Sales_Order = SH.Sales_Order
    Group by J.Order_Date
    )q
    on p.[Order Date] = q.[Order Date]
    Order by COALESCE(p.[Order Date],q.[Order Date]) Desc
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to modify a row from a table?

    Hi experts!
    I've a doubt, I need to modify a table with some information I've search, if I do the code below, my program works slowly because the tabla ITDATOS has 650 rows... so, the problem is, how can I modify this in another way?
    FORM RELLENA_DATOS_GENERALES USING PERSONAL.
    DATA: UNIDAD TYPE P0001-ORGEH.
    DATA: TEXTO TYPE HRP1000-STEXT.
    data: indice type sy-index.
      LOOP AT ITDATOS.
      indice = sy-index.
    * Nombre, grupo de personal y área de personal.
        LOOP AT P0001 WHERE PERNR EQ ITDATOS-PERNR.
    *      AND
    *                                   BEGDA LT FECHA-HIGH AND
    *                                   ENDDA GT FECHA-LOW.
    * Nos quedamos con el último resgistro que existe en la fecha seleccionada por pantalla.
          ITDATOS-ENAME = P0001-ENAME.
          ITDATOS-PERSG = P0001-PERSG.
          ITDATOS-PERSK = P0001-PERSK.
        ENDLOOP.
    * Dni.
        LOOP AT P0002 WHERE PERNR EQ ITDATOS-PERNR.
    *      AND
    *                                   BEGDA LT FECHA-HIGH AND
    *                                   ENDDA GT FECHA-LOW.
    * Nos quedamos con el último resgistro que existe en la fecha seleccionada por pantalla.
          ITDATOS-PERID = P0002-PERID(9).
        ENDLOOP.
        LOOP AT P0050 WHERE PERNR EQ ITDATOS-PERNR.
    *      AND
    *                                   BEGDA LT FECHA-HIGH AND
    *                                   ENDDA GT FECHA-LOW.
    * Nos quedamos con el último resgistro que existe en la fecha seleccionada por pantalla.
          ITDATOS-ZAUSW = P0050-ZAUSW.
        ENDLOOP.
    * Recogemos el dato de departamento del infotipo 0001
        SELECT SINGLE ORGEH FROM PA0001 INTO UNIDAD WHERE PERNR EQ ITDATOS-PERNR.
        SELECT SINGLE STEXT FROM HRP1000 INTO TEXTO WHERE OBJID EQ UNIDAD AND
                                                          PLVAR EQ '01'   AND
                                                          LANGU EQ 'S'.
        ITDATOS-DEPART = TEXTO.
    * Insertamos datos modificando tabla ITDATOS ya existente con la información específica.
        MODIFY ITDATOS index indice.
      ENDLOOP.
    ENDFORM.                    " RELLENA_DATOS_GENERALES
    Thanks a lot,
    Regards,
    Rebeca

    Hi,
    Take another internal table and work area same as the initial internal table and work area used in screen 8002 which is to be used to delete the selected data.
    Take the names of the input/output fields as work_area-field_name and select column in table control as work_area-flag.
    Also take a flag field of size 1 datatype character as the last field in the internal table and work area while declaration.
    You have to pass a code in PBO of the screen for reading internal table into the table control.
    So it reads the internal table into the table control whenever you perform any action on use command.
    All you need to do is to write a code to modify the internal table form the table control while performing any user action.
    At screen logic,
    PROCESS BEFORE OUTPUT.
      MODULE status_8002. "for pf-status
      LOOP WITH CONTROL po_tab. "po_tab is table control
        MODULE pass_data. "to pass data into table control from internal table
      ENDLOOP.
    PROCESS AFTER INPUT.
      MODULE user_command_8002. "for user command(back and exit)
      LOOP WITH CONTROL po_tab.
        MODULE modify_data. "to modify data from table control into table control
      ENDLOOP.
    In PBO,
    *&      Module  STATUS_8002 OUTPUT
    MODULE status_8002 OUTPUT.
      SET pf-status 'ZAB_PFSTA'. " pf-status
      DATA : line_count TYPE i.
      DESCIRBE TABLE it_ekpo
      LINES line_count.
      po_tab-lines = line_count + 10.
      " to make table control scrollable
    ENDMODULE.                 " STATUS_8002  OUTPUT
    *&      Module  PASS_DATA  OUTPUT
    MODULE pass_data OUTPUT.
      READ TABLE it_ekpo into wa_ekpo INDEX po_tab-current_line.
    ENDMODULE.                 " PASS_DATA  OUTPUT
    "it_ekpo is internal table and wa_ekpo is the work area
    In PAI,
    *&      Module  MODIFY_DATA  INPUT
    MODULE MODIFY_DATA INPUT.
      MODIFY IT_EKPO INDEX PO_TAB-CURRENT_LINE FROM WA_EKPO.
      "modify records from table control into the internal table
    ENDMODULE.                 " MODIFY_DATA  INPUT
    Now at PAI, if you done any changes in the table control, then all these changes will be reflected to the internal table, and PBO will read the modified internal table.
    Hope this solves your problem.
    Thanks & Regards,
    Tarun Gambhir

  • Return the Minimum from two tables in a Union

    Hello
    I have written a simple union query from our dialler service which has 2 tables, in inbound and an outbound table. A lead can show in any table depending how they came through to an agent and they can also show in both tables.  I need to return the
    the first instance in the calltime column from both tables but also return all the other information.  I'm expecting multiple entries for the minimum calltime which is fine, I will be using a lookup in excel to extract the time.  Just to make matters
    a little more difficult i'm having to use the OPENQUERY function because its within MYSQL.
    SELECT O.Lead, O.DataList, O.[CallTime] AS 'CallDate', O.[Status], O.Uniqueid, O.Campaign, O.number, O.Advisor, 'Outbound' AS CallType
    FROM OPENQUERY (dialler, 'SELECT * FROM dialler_outbound_data') O
    WHERE O.CallTime >= '2014-12-01'
    UNION
    SELECT I.Lead, I.DataList, [CallTime] AS 'CallDate', I.[Status], I.Uniqueid, I.Campaign, I.Number, I.Advisor, 'Inbound' AS CallType
    FROM OPENQUERY (dialler, 'SELECT * FROM dialler_inbound_data') I
    WHERE I.CallTime >= '2014-12-01'
    Can anyone help please?
    Many Thanks
    Rich

    Hi Rich,
    The use of the ROW_NUMBER function as mentioned and temp tables should do the trick.  See the code below...hope this helps.
    SELECT ROW_NUMBER() OVER(ORDER BY O.[CallTime]) as 'Occurrance'
    ,O.Lead
    ,O.DataList
    ,O.[CallTime] AS 'CallDate'
    ,O.[Status]
    ,O.Uniqueid
    ,O.Campaign
    ,O.number
    ,O.Advisor
    ,'Outbound' AS CallType
    INTO #TEMP1
    FROM OPENQUERY (dialler, 'SELECT * FROM dialler_outbound_data') O
    WHERE O.CallTime >= '2014-12-01'
    SELECT ROW_NUMBER() OVER(ORDER BY I.[CallTime]) as 'Occurrance'
    ,I.Lead
    ,I.DataList
    ,[CallTime] AS 'CallDate'
    ,I.[Status]
    ,I.Uniqueid
    ,I.Campaign
    ,I.Number
    ,I.Advisor
    ,'Inbound' AS CallType
    INTO #TEMP2
    FROM OPENQUERY (dialler, 'SELECT * FROM dialler_inbound_data') I
    WHERE I.CallTime >= '2014-12-01'
    INSERT INTO #FINAL
    SELECT * FROM #TEMP1
    UNION
    SELECT * FROM #TEMP2
    SELECT * FROM #FINAL AS F WHERE F.Occurrance = 1
    I'm new to this so if this helps, I could use your vote. 
    Thanks,
     Zach

  • How to find different rows in two tables which have same schema.

    There are two tables t1 and t2, they have same schema. Table t1 includes the informtion of students last month,table t2 incude the information of the students this month. I want to find the difference of the same student between two months. What should I do and How to do?

    Look a the following example:
    Table TEST_1 TEST_2
    ID ID_TX        ID ID_TX
    1 a                   1 a
    2 b                   2 b
    4 d                   4 d
    6 f                    6 f
    7 g                   7 g
    10 j                  10 j
    10 Z                10 x --- DIFFERENT
    12 x                         --- DIFFERENT
                           20 x ---- DIFFERENT
    Query:
            Select * FROM
                 ( (SELECT '1', ID, ID_TXT FROM TEST_1 MINUS SELECT '1', ID, ID_TXT FROM TEST_2)
                  UNION
                   (SELECT '2', ID, ID_TXT FROM TEST_2 MINUS SELECT '2', ID, ID_TXT FROM TEST_1) )
            Order By ID
    RESULTS:
    '        ID ID_TXT
    1        10 Z
    2        10 x
    1        12 x
    2        20 x

  • How to use common object from two tables with out join.

    HI,
    I have two tables called A & B In A table i have the following objects
    1.weekend
    2.S1(measure)
    3.S2(measure)
    4.S3(measure)
    5.S4(measure)
    And In B table i have followning columns
    1.week end
    2.p1(measure)
    3.p2(measure)
    4.p3(measure)
    5.p4(measure)
    Now in universe i created all the measure objects i.e.s1,s2,s3,s4,p1,p2,p3,p4 A.weekend,B.weekend.
    instead of using week end two times i wnt to use only once because this is common in both table.
    if i use join between these tables i am getting values fine
    But With out join is there any thing to do in universe level to create common objects to use from both the tables..I tried using aggregate awareness but while reporting it is taking as two SQL.which is not synchronized.
    Please help me on this ...

    hi,
    Although  Weekend column is present in both tables, by creating a single Object in Universe, Universe can identify relationship with only table referenced in Object Creation.
    So, there will be no identification of relationship with other table measures.
    Obviously, you need to create 2 Weekend objects in Universe (in two classes).
    Case 1: You need not join these two tables in Universe. When you create 2 Queries in WEBI, automatcially Weekend objects are synchronized (if both are of same datatype)
    Case 2: If you join these two tables in Universe, Obviously,
    your SQL may contain Weekend from Table1, measures from Table 2
    or
    your SQL may contain Weekend from Table2, measures from Table 1
    Finally, You need to create 2 objects in Universe. But your query may contain a single Object based on Case 2.
    Regards,
    Vamsee

  • How to delete a row from database table in facade client

    Hi all,
    I followed the tutorial in creating a persistence entity from database table, then a session facade. Then I followed the tutorial to create a sample client to test the model. In the session facade, I could use persistEntity method to insert a record to the database. I am just thinking of an extension to the tutorial, i.e., being able to delete the record too. So I created a new method removeEntity in the session facade
    public void removeEntity(Object entity) {
    entity=em.merge(entity);
    em.remove(entity);
    em.flush();
    and called it in the sample client. It was executed without any error, but the record in the table still exists.
    I tried to look around for a solution, but I did not find one. Would anybody here please help out? Many thanks in advance!

    Hi Frank,
    I tried the code snippet, but I got the following exception when executing this code:
    javax.ejb.EJBException: EJB Exception: ; nested exception is:
         java.lang.IllegalStateException: The method public abstract javax.persistence.EntityTransaction javax.persistence.EntityManager.getTransaction() cannot be invoked in the context of a JTA EntityManager.; nested exception is: java.lang.IllegalStateException: The method public abstract javax.persistence.EntityTransaction javax.persistence.EntityManager.getTransaction() cannot be invoked in the context of a JTA EntityManager.
    java.lang.IllegalStateException: The method public abstract javax.persistence.EntityTransaction javax.persistence.EntityManager.getTransaction() cannot be invoked in the context of a JTA EntityManager.
         at weblogic.deployment.BasePersistenceContextProxyImpl.validateInvocation(BasePersistenceContextProxyImpl.java:121)
         at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:86)
         at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:91)
         at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:80)
         at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:26)
         at $Proxy141.getTransaction(Unknown Source)
         at model.SessionEJBBean.removeEntity(SessionEJBBean.java:60)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
         at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:55)
         at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
         at $Proxy143.removeEntity(Unknown Source)
         at model.SessionEJB_qxt9um_SessionEJBImpl.removeEntity(SessionEJB_qxt9um_SessionEJBImpl.java:142)
         at model.SessionEJB_qxt9um_SessionEJBImpl_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
         at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
         at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    javax.ejb.EJBException: EJB Exception: ; nested exception is:
         java.lang.IllegalStateException: The method public abstract javax.persistence.EntityTransaction javax.persistence.EntityManager.getTransaction() cannot be invoked in the context of a JTA EntityManager.; nested exception is: java.lang.IllegalStateException: The method public abstract javax.persistence.EntityTransaction javax.persistence.EntityManager.getTransaction() cannot be invoked in the context of a JTA EntityManager.
         at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:109)
         at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:91)
         at $Proxy0.removeEntity(Unknown Source)
         at model.SessionEJBClient.main(SessionEJBClient.java:71)
    Caused by: java.lang.IllegalStateException: The method public abstract javax.persistence.EntityTransaction javax.persistence.EntityManager.getTransaction() cannot be invoked in the context of a JTA EntityManager.
         at weblogic.deployment.BasePersistenceContextProxyImpl.validateInvocation(BasePersistenceContextProxyImpl.java:121)
         at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:86)
         at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:91)
         at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:80)
         at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:26)
         at $Proxy141.getTransaction(Unknown Source)
         at model.SessionEJBBean.removeEntity(SessionEJBBean.java:60)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
         at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:55)
         at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
         at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
         at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
         at $Proxy143.removeEntity(Unknown Source)
         at model.SessionEJB_qxt9um_SessionEJBImpl.removeEntity(SessionEJB_qxt9um_SessionEJBImpl.java:142)
         at model.SessionEJB_qxt9um_SessionEJBImpl_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
         at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
         at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Process exited with exit code 0.

  • How to select x numbered row from two tables

    Hi,
    I have one performance problem...
    Here is sample scenario...
    TableA
    A1 A2 A3
    a1     a12     a13
    a2     a22     a23
    a3     a32     a33
    TableB
    B1     B2     B3
    b1     b12     b13
    b2     b22     b23
    I want result like
    A1     B1     A2     B2
    a1     b1     a12     b12
    a2     b2     a22     b22
    I have written it like
    select
    A1,
    B1,
    A2,
    B2
    from
    (select A1, A2, rownum rnA from TableA) a,
    (select B1, B2, rownum rnB from TableB) b
    where rnA = rnB
    but suppose TableA has 2500000 rows and
    TableB has 500 rows then for 500 rows I have to
    wait for all 2500000 rows scanning.
    Is there any smart solution..?
    I have created indexes for on columns A1, (A1,A2,A3), B1, (B1,B2,B3).
    Curious:)
    Rushang Kansara
    Message was edited by:
    Rushang Kansara

    Here is explain plan
    SELECT STATEMENT, GOAL = FIRST_ROWS               Cost=5     Cardinality=67     Bytes=3618
    HASH JOIN               Cost=5     Cardinality=67     Bytes=3618
    VIEW     Object owner=SFMFG          Cost=2     Cardinality=82     Bytes=2214
    COUNT                         
    TABLE ACCESS FULL     Object owner=SFMFG     Object name=TABLEA     Cost=2     Cardinality=82     Bytes=1148
    VIEW     Object owner=SFMFG          Cost=2     Cardinality=82     Bytes=2214
    COUNT                         
    TABLE ACCESS FULL     Object owner=SFMFG     Object name=TABLEB     Cost=2     Cardinality=82     Bytes=1148
    New to sql tunning Here why cardinality goes to 67 and cost to 5???
    Thank you for your time.. :)

  • How to get the rows from a table having some column has any letter

    Hi All,
    suppose i have a table having columns id(number), code(varchar).
    code has alphanumeric characters (ex. ABC123, 67B56 etc).
    some codes are only numbers (2344, 7898 etc).
    how can i get the rows which have alphabets in the code.
    ex:
    id code
    1 AB45
    2 456
    3 890
    4 67B7
    how can i write a query such that it should give me the ids 1 and 4 (as they have alphabets in code)
    thanks in advance to all

    Thanks to one and all.
    i am gettig my required output.
    But i have a doubt in the operator.
    If i add or remove '[]' in the operator, i am getting different ouputs.
    There is a count difference in the result of the operators used.
    REGEXP_LIKE(<column>,'[[:lower:]]')
    REGEXP_LIKE(<column>,'[[[:lower:]]]')
    REGEXP_LIKE(<column>,'[:lower:]')
    Can anybody please explain what is the difference in using '[]', in the operator?
    What is the correct syntax, whether i have to use two '[]'s or one '[]'.
    Also, can i use REGEXP_LIKE() in oracle 8i version.( I am unable to use the operator in 8i)?
    Any query to get the required output in 8i version?
    Thanks in advance to all.

Maybe you are looking for