SQL Query to find the Delta between 2 rows

Can the below be possible? If so can you help me writing aSQL Query to do so…
I have data in spreadsheet which is pulled off from the database (data from more than one table with joins); send it to the different teams. They will check the data n update the spreadsheet if necessary and send it back to me.
I have to find the changes and update the database from the provided spreadsheet accordingly. Changes can be on different columns on each set of row.
Example:
DataFrom
ServerName
Branch_Name
Application_Name
Server Status
Application_Status
App_Environment
Tier
SQL Query
abcdef
app
adp
Deployed
Deployed
Production
silver
Excel
abcdef
app
adp
Deployed
Deployed
Development
Bronze
DataFrom
ServerName
Branch_Name
Application_Name
Server Status
Application_Status
App_Environment
Tier
SQL Query
Hijkl
app
adp
Deployed
Deployed
Production
Gold
Excel
Hijkl
app
Dep
Deployed
Deployed
Production
Gold
DataFrom
ServerName
Branch_Name
Application_Name
Server Status
Application_Status
App_Environment
Tier
SQL Query
Xzy
app
Dep
Deployed
Deployed
Production
Silver
Excel
Xzy
App
Dep
Deployed
Deployed
Development
Silver
Above scenario is an example what I am look to do with sql script? Opinions/queries accepted…
There are 1200+ rows to compare it manually which is a pain.
Thanks.

Columns are different, when the contain multiple distinct values.
SELECT COUNT(DISTINCT Name) ,
COUNT(DISTINCT GroupName) ,
COUNT(*)
FROM HumanResources.Department;
Without a concise and complete example (table DDL and sample data insert statements), it's hard to tell what the correct solution could be..
DECLARE @Sample TABLE ( SetID INT, ServerID INT, ApplicationID INT );
INSERT INTO @Sample
VALUES ( 1, 1, 1 ),
( 1, 1, 1 ),
( 2, 1, 1 ),
( 2, 1, 2 ),
( 3, 1, 1 ),
( 3, 2, 1 );
WITH Evaluate AS
SELECT SetID,
COUNT(DISTINCT ServerID) AS Servers,
COUNT(DISTINCT ApplicationID) AS Applications
FROM @Sample
GROUP BY SetID
SELECT S.*,
CASE WHEN E.Servers != 1 THEN 1 ELSE 0 END AS ServersDifferent,
CASE WHEN E.Applications != 1 THEN 1 ELSE 0 END AS ApplicationsDifferent
FROM @Sample S
INNER JOIN Evaluate E ON S.SetID = E.SetID
ORDER BY S.SetID;

Similar Messages

  • Write the sql query to find largest value in row wise without using   great

    write the sql query to find largest value in row wise without using
    greatest fuction?

    Another not so good way, considering you want greatest of 4 fields from a single record:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (Select 100 col1,200 col2,300 col3,400 col4 from dual
      2  union select 500,600,700,800 from dual
      3  union select 900,1000,1100,1200 from dual
      4  union select 1300,1400,1500,1600 from dual
      5  union select 1700,1800,1900,2000 from dual
      6  union select 2100,2200,2300,2400 from dual
      7  union select 2800,2700,2600,2500 from dual
      8  union select 2900,3000,3100,3200 from dual)
      9  SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) Max_value
    10  FROM
    11  (SELECT (CASE WHEN col1_col2 > col2_col3 THEN col1_col2 ELSE col2_col3 END) col1,
    12         (CASE WHEN col2_col3 > col3_col4 THEN col2_col3 ELSE col3_col4 END) col2,
    13         (CASE WHEN col3_col4 > col4_col1 THEN col3_col4 ELSE col4_col1 END) col3
    14  FROM
    15  (SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) col1_col2,
    16         (CASE WHEN col2 > col3 THEN col2 ELSE col3 END) col2_col3,
    17         (CASE WHEN col3 > col4 THEN col3 ELSE col4 END) col3_col4,
    18         (CASE WHEN col4 > col1 THEN col4 ELSE col1 END) col4_col1
    19* FROM t))
    SQL> /
    MAX_VALUE
           400
           800
          1200
          1600
          2000
          2400
          2800
          3200
    8 rows selected.
    SQL> Edited by: AP on Sep 21, 2010 6:29 AM

  • Sql query to find the balances for a customer account wise.

    Hi,
    Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
    presently we are using this query, but the output doesnot return the expected result.
    SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
    FROM      ra_cust_trx_line_gl_dist_all gld,
              gl_code_combinations c,
              ar_payment_schedules_all ps,
              RA_CUSTOMER_TRX_ALL rat,
              ra_customers rc
    WHERE      c.CHART_OF_ACCOUNTS_ID = 101
    and gld.code_combination_id = c.code_combination_id
         and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
         and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
    and ps.customer_id=rc.customer_id
         and ps.status='OP'
         and ps.gl_date <= :PDATE
         and ps.org_id=:PORGID
         and ps.class in ('GUAR','INV','DM','DEP')
    and c.SEGMENT4=:Account_id
    and ps.customer_id=:Customer_id
    Thanks in advance.
    Kalyan.

    Can someone help us with this.

  • Can anybody provide the SQL query to find the files uploaded in a particular folder?

    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

    Nevin,
    Be great if we could know the version of Portal. For Rel. 1, here's the query
    select id,masterthingid from wwv_things
    where siteid = &site
    and cornerid = &corner
    &site - Content Area id
    &corner - Folder id
    if you don't know the folder id, use
    select id from wwv_corners where siteid = &site
    and name = &folder
    Hope this helps. I have run into this situation before. Usually, the culprits were
    one of the following:
    1. Junk Characters in description of item (caused due to Copy-Paste)
    2. Special Characters in the File name
    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

  • Sql query to find the space in between the sentense

    hi,
    can anybody tell me the query to find the space in between the data
    chandan

    Not sure what you mean, but you might want to take a look at INSTR, like in
    instr (txt, ' ')

  • Query to find the difference between the last date and the second to the last date

    Hi all,
    Hope all is well.
    I am working on the following problem because I am trying to improve my MS SQL skills. But I am stuck at the moment and I wonder if you could provide some assistance please. Here is the issue:
    Table 1: Dividends
    divId
    ExDate
    RecordDate
    PayDate
    Amount
    Yield
    symId
    1
    2013-02-19
    2013-02-21
    2013-03-14
    0.23
    0.00000
    3930
    2
    2012-11-13
    2012-11-15
    2012-12-13
    0.23
    0.00849
    3930
    3
    2012-08-14
    2012-08-16
    2012-09-13
    0.20
    0.00664
    3930
    4
    2012-05-15
    2012-05-17
    2012-06-14
    0.20
    0.00662
    3930
    5
    2012-02-14
    2012-02-16
    2012-03-08
    0.20
    0.00661
    3930
    6
    2011-11-15
    2011-11-17
    2011-12-08
    0.20
    0.00748
    3930
    7
    2011-08-16
    2011-08-18
    2011-09-08
    0.16
    0.00631
    3930
    8
    2011-05-17
    2011-05-19
    2011-06-09
    0.16
    0.00653
    3930
    9
    2011-02-15
    2011-02-17
    2011-03-10
    0.16
    0.00594
    3930
    10
    2010-11-16
    2010-11-18
    2010-12-09
    0.16
    0.00620
    3930
    11
    2010-08-17
    2010-08-19
    2010-09-09
    0.13
    0.00526
    3930
    12
    2010-05-18
    2010-05-20
    2010-06-10
    0.13
    0.00455
    3930
    13
    2010-02-16
    2010-02-18
    2010-03-11
    0.13
    0.00459
    3930
    Table 2: Tickers
    symId
    Symbol
    Name
    Sector
    Industry
    1
    A
    Agilent Technologies Inc.
    Technology
    Scientific & Technical Instruments
    2
    AA
    Alcoa, Inc.
    Basic Materials
    Aluminum
    3
    AACC
    Asset Acceptance Capital Corp.
    Financial
    Credit Services
    4
    AADR
    WCM/BNY Mellon Focused Growth ADR ETF
    Financial
    Exchange Traded Fund
    5
    AAIT
    iShares MSCI AC Asia Information Tech
    Financial
    Exchange Traded Fund
    6
    AAME
    Atlantic American Corp.
    Financial
    Life Insurance
    7
    AAN
    Aaron's, Inc.
    Services
    Rental & Leasing Services
    8
    AAON
    AAON Inc.
    Industrial Goods
    General Building Materials
    9
    AAP
    Advance Auto Parts Inc.
    Services
    Auto Parts Stores
    10
    AAPL
    Apple Inc.
    Technology
    Personal Computers
    11
    AAT
    American Assets Trust, Inc.
    Financial
    REIT - Office
    12
    AAU
    Almaden Minerals Ltd.
    Basic Materials
    Industrial Metals & Minerals
    I am trying to check the last date (i.e. max date) and also check the penultimate date (i.e. the second to the last date).  And then find the difference between the two (i.e. last date minus penultimate
    date).
    I would like to do that for each of the companies listed in Table 2: Tickers.  I am able to do it for just one company (MSFT) using the queries below:
    SELECT
    [First] = MIN(ExDate),
    [Last] = MAX(ExDate),
    [Diff] = DATEDIFF(DAY, MIN(ExDate), MAX(ExDate))
    FROM (
    SELECT TOP 2 Dividends.ExDate
    FROM Dividends, Tickers
    WHERE Dividends.symId=Tickers.symId
    AND Tickers.Symbol='MSFT'
    ORDER BY ExDate DESC
    ) AS X
    Outputs the following result:
    First
    Last
    Diff
    2012-11-13
    2013-02-19
    98
    But what I would like instead is to be able to output something like this:
    Symbol
    First
    Last
    Diff
    MSFT
    2012-11-13
    2013-02-19
    98
    AAN
    2012-11-13
    2012-12-14
    1
    X
    2012-11-13
    2012-12-14
    1
    Can anyone please let me know what do I need to add on my query in order to achieve the desired output?
    Any help would be greatly appreciated.
    Thanks in advance. 

    Could you try this?
    create table Ticker (SymbolId int identity primary key, Symbol varchar(4))
    insert into Ticker (Symbol) values ('MSFT'), ('ORCL'), ('GOOG')
    create table Dividend (DividendId int identity, SymbolId int constraint FK_Dividend foreign key references Ticker(SymbolId), ExDate datetime, Amount decimal(18,4))
    insert into Dividend (SymbolId, ExDate, Amount) values
    (1, '2012-10-1', 10),
    (1, '2012-10-3', 1),
    (1, '2012-10-7', 7),
    (1, '2012-10-12', 2),
    (1, '2012-10-23', 8),
    (1, '2012-10-30', 5),
    (2, '2012-10-1', 10),
    (2, '2012-10-6', 1),
    (2, '2012-10-29', 7),
    (3, '2012-10-1', 22),
    (3, '2012-10-3', 21),
    (3, '2012-10-7', 3),
    (3, '2012-10-12', 9)
    WITH cte
    AS (SELECT t.Symbol,
    d.ExDate,
    d.Amount,
    ROW_NUMBER()
    OVER (
    partition BY Symbol
    ORDER BY ExDate DESC) AS rownum
    FROM Ticker AS t
    INNER JOIN Dividend AS d
    ON t.SymbolId = d.SymbolId),
    ctedate
    AS (SELECT Symbol,
    [1] AS maxdate,
    [2] AS penultimatedate
    FROM cte
    PIVOT( MIN(ExDate)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery),
    cteamount
    AS (SELECT Symbol,
    [1] AS maxdateamount,
    [2] AS penultimatedateamount
    FROM cte
    PIVOT( MIN(Amount)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery)
    SELECT d.Symbol,
    MIN(MaxDate) AS maxdate,
    MIN(penultimatedate) AS penultimatedate,
    DATEDIFF(d, MIN(penultimatedate), MIN(MaxDate)) AS numberofdays,
    MIN(MaxDateAmount) AS maxdateamount,
    MIN(penultimatedateAmount) AS penultimatedateamount,
    MIN(MaxDateAmount) - MIN(penultimatedateAmount) AS delta
    FROM ctedate AS d
    INNER JOIN cteamount AS a
    ON d.Symbol = a.symbol
    GROUP BY d.Symbol
    ORDER BY d.Symbol
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers.
    Thanks!
    Aalam | Blog (http://aalamrangi.wordpress.com)

  • Need a sql query to get the difference between two timestamp in the format of hh:mm:ss.msec

    I have a database table where it keeps record of the transaction when it starts at StartTime and when it ends at EndTime. Both these entries are having the timestamp entries. Say for example, I have a tuple with Entries like 'Transaction A' starts at '2014-05-07
    20:55:03.170' and ends at '2014-05-08 08:56:03.170'. I need to find the difference between these two timestamps and my expected output is 12:01:00.000. Let me know how to achieve this ? 

    Hi,
    You can use below script which calculates difference as DD:HH:MM:SS. You can modify the same:
    DECLARE @startTime DATETIME
    DECLARE @endTime DATETIME
    SET @startTime = '2013-11-05 12:20:35'
    SET @endTime = '2013-11-10 01:22:30'
    SELECT [DD:HH:MM:SS] =
    CAST((DATEDIFF(HOUR, @startTime, @endTime) / 24) AS VARCHAR)
    + ':' +
    CAST((DATEDIFF(HOUR, @startTime, @endTime) % 24) AS VARCHAR)
    + ':' +
    CASE WHEN DATEPART(SECOND, @endTime) >= DATEPART(SECOND, @startTime)
    THEN CAST((DATEDIFF(MINUTE, @startTime, @endTime) % 60) AS VARCHAR)
    ELSE
    CAST((DATEDIFF(MINUTE, DATEADD(MINUTE, -1, @endTime), @endTime) % 60)
    AS VARCHAR)
    END
    + ':' + CAST((DATEDIFF(SECOND, @startTime, @endTime) % 60) AS VARCHAR),
    [StringFormat] =
    CAST((DATEDIFF(HOUR , @startTime, @endTime) / 24) AS VARCHAR) +
    ' Days ' +
    CAST((DATEDIFF(HOUR , @startTime, @endTime) % 24) AS VARCHAR) +
    ' Hours ' +
    CASE WHEN DATEPART(SECOND, @endTime) >= DATEPART(SECOND, @startTime)
    THEN CAST((DATEDIFF(MINUTE, @startTime, @endTime) % 60) AS VARCHAR)
    ELSE
    CAST((DATEDIFF(MINUTE, DATEADD(MINUTE, -1, @endTime), @endTime) % 60)
    AS VARCHAR)
    END +
    ' Minutes ' +
    CAST((DATEDIFF(SECOND, @startTime, @endTime) % 60) AS VARCHAR) +
    ' Seconds '
    Reference:
    http://sqlandme.com/2013/12/23/sql-server-calculating-elapsed-time-from-datetime/
    - Vishal
    SqlAndMe.com

  • SQL Query to find the Notify upon Completion employees

    Hi,
    I am looking for a query to find the names of the employees/users who are notified upon the completion of the Concurrent Programs. I know how to find the concurrent program details but not able to find notify upon completion employees details. Please help me.
    Thanks,
    KM

    Thanks Scott for responding. There is no any custom code. Here is the navigation to reach there:
    System Administrator -> Requests -> View -> Specific Requests -> Open any request ->View Details -> Options -> Notify the following people
    I am looking for the query to find these notified people using SQL Query.Query FND_CONCURRENT_REQUESTS table (NOTIFY_ON_PP_ERROR column) -- http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_REQUESTS&c_owner=APPLSYS&c_type=TABLE
    Thanks,
    Hussein

  • Hierarchical query To find the relation between the tables

    Hi,
    In my database schema i have hundreds of tables and dont have data model to understand the relation between them.
    I heared that there will be heirarchical query which can be written by using meta tables, is this query will really help me to understand the relations.
    Can anybody please help to get this query.
    Thanks,
    Vinod

    >
    Hi Vinod,
    I heared that there will be heirarchical query which can be written
    by using meta tables, is this query will really help me to understand the relations.You could also download Data Modeler - it should be of assistance - free from
    Oracle.
    HTH,
    Paul...
    Vinod

  • SQL query  update to the Effective Dated Row in PS_JOB table?  SQL Server

    Hi,
    I have a requirement to update the Holiday Schedule field in the maximum effective date row based on the criteria: EMPL_RCD and BUSINESS_UNIT.
    Initially I ran a select query to see how many rows will gets affected.It fetched rows properly with the criteria.
    When I am trying to update the query with the same criteria its showing error message.
    But I don't find any mistake in my query...
    Here is the query I have used:
    UPDATE PS_JOB J SET J.HOLIDAY_SCHEDULE='HLDY' WHERE
    J.EFFDT=(SELECT MAX(A.EFFDT) FROM PS_JOB A
    WHERE A.EMPLID=J.EMPLID
    AND A.EMPL_RCD=J.EMPL_RCD
    AND A.EFFDT<=GETDATE())
    AND J.EFFSEQ=
    (SELECT MAX(A1.EFFSEQ) FROM PS_JOB A1
    WHERE A1.EMPLID=J.EMPLID
    AND A1.EMPL_RCD=J.EMPL_RCD
    AND A1.EFFDT=J.EFFDT)
    AND J.BUSINESS_UNIT='HLDY1'
    AND J.EMPL_RCD=0
    Try with differnt ways but no result. Could anyone please guide me how I can update it....
    Thanks in Advance!

    My database is MY SQL server.
    I found the issue and it is working now. Update syntax works diffrently when we use alias name in set column.
    UPDATE PS_JOB SET HOLIDAY_SCHEDULE='HLDY' FROM PS_JOB J WHERE
    J.EFFDT=(SELECT MAX(A.EFFDT) FROM PS_JOB A
    WHERE A.EMPLID=J.EMPLID
    AND A.EMPL_RCD=J.EMPL_RCD
    AND A.EFFDT<=GETDATE())
    AND J.EFFSEQ=
    (SELECT MAX(A1.EFFSEQ) FROM PS_JOB A1
    WHERE A1.EMPLID=J.EMPLID
    AND A1.EMPL_RCD=J.EMPL_RCD
    AND A1.EFFDT=J.EFFDT)
    AND J.BUSINESS_UNIT='HLDY1'
    AND J.EMPL_RCD=0
    This has worked in SQL server.
    Thanks for looking into this.

  • Sql query to find the scheduled date

    I schedule a job for last Thursday of every month. Based on my current date and time I need the date of my next scheduled run of the job...
    (i.e) If today is 28-march-2012 (Wednesday) my query should return 3/29/12(which is the last thursday of the month)
    If today is 30-march-2012 (Friday) my query should return 4/26/12 (which is the last thursday of next month)
    If today is 29-march-2012 and time is 11:00 AM and i have scheduled a job to run at 12:00 PM of last thursday of every month then my query should return 3/29/12
    If today is 29-march-2012 and time is 1:00 PM then my query should return 4/26/12

    924163 wrote:
    I schedule a job for last Thursday of every month. Based on my current date and time I need the date of my next scheduled run of the job...
    (i.e) If today is 28-march-2012 (Wednesday) my query should return 3/29/12(which is the last thursday of the month)
    If today is 30-march-2012 (Friday) my query should return 4/26/12 (which is the last thursday of next month)
    If today is 29-march-2012 and time is 11:00 AM and i have scheduled a job to run at 12:00 PM of last thursday of every month then my query should return 3/29/12
    If today is 29-march-2012 and time is 1:00 PM then my query should return 4/26/12may be
    SQL> ed
    Wrote file afiedt.buf
      1  with tmp as
      2  (
      3  select to_date('28-march-2012','DD-month-YYYY') dt from dual union all
      4  select to_date('29-march-2012 11:00:00 AM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
      5  select to_date('29-march-2012 1:00:00 PM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
      6  select to_date('29-march-2012 12:00:00 PM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
      7  select to_date('29-march-2012 11:59:00 AM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
      8  select to_date('30-march,2012','DD-month-YYYY') dt from dual
      9  )
    10  select dt,
    11         case
    12           when Next_day(Add_months(Trunc(dt, 'MM'), 1) - 7, 'thursday') + ( 12 /
    13                24 ) >
    14                dt then Next_day(Add_months(Trunc(dt, 'MM'), 1) - 7, 'thursday')
    15           else Next_day(Add_months(Trunc(dt, 'MM'), 2) - 7, 'thursday')
    16         end new_dat
    17  from   tmp
    18* order  by dt
    SQL> /
    DT                      NEW_DAT
    28-Mar-2012 12:00:00 AM 29-Mar-2012 12:00:00 AM
    29-Mar-2012 11:00:00 AM 29-Mar-2012 12:00:00 AM
    29-Mar-2012 11:59:00 AM 29-Mar-2012 12:00:00 AM
    29-Mar-2012 12:00:00 PM 26-Apr-2012 12:00:00 AM
    29-Mar-2012 01:00:00 PM 26-Apr-2012 12:00:00 AM
    30-Mar-2012 12:00:00 AM 26-Apr-2012 12:00:00 AM
    6 rows selected.
    SQL>

  • Sql query to find the last word in a sentence (column)

    Hi,
    I have to retrieve the last word in a column containing varchar2(text) values.
    If anyone knows the query for this kindly share with me.

    There's also the option of regular expressions in 10g onwards...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'oracle forums is the best resource for oracle intelligence' as l from dual)
      2  select regexp_replace(l, '[[:print:]]* ([^ ]*)$','\1') as l
      3* from t
    SQL> /
    L
    intelligence
    SQL>

  • SQL query to find differences (changes) between tables (from one table) where field names are different

    Hi All,
    I am looking to create a view which returns new or modified data (differences) based on a comparison between two tables.
    The EMP_SOURCE table stores all employee data including duplicate staff numbers (STAFFNO):
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    ) ON [PRIMARY]
    GO
    The EMP table stores unique staff numbers. This is the table used by the application.
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL,
    CONSTRAINT [PK_EMP] PRIMARY KEY CLUSTERED
    [EMP_ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    We are looking to migrate data from EMP_SOURCE to EMP but only records which are new in EMP_SOURCE and do not exist in EMP or records which are different in EMP_SOURCE from EMP.
    EMP_SOURCE:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    John Smith
    Manager
    London
    UK
    1087
    Beth King
    Analyst
    New York
    USA
    2095
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Beth King
    Junior
    Washington
    USA
    2095
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    EMP:
    EMP_ID
    EMP_NAME
    EMP_TITLE
    EMP_OFFICE
    EMP_COUNTRY
    EMP_NUMBER
    1
    John Smith
    Manager
    London
    UK
    1087
    2
    Beth King
    Analyst
    New York
    USA
    2095
    3
    Karl Bent
    Manager
    Washington
    USA
    1106
    Based on the above comparison, EMP_SOURCE table has the following differences:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Differences in red. Beth King should be completely ignored because of duplicate staff numbers (EMP_NUMBER).
    Any help to create a view which returns only the differences from EMP_SOURCE would be appreciated.
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');

    HI Manc !
    You may use the below code to get your desired output;
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    GO
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');
    SELECT FULLNAME,JOBTITLE,LOCATION,COUNTRY,STAFFNO FROM EMP_SOURCE
    EXCEPT
    SELECT EMP_NAME,EMP_TITLE,EMP_OFFICE,EMP_COUNTRY,EMP_NUMBER FROM Emp
    Please let me know if this doesn’t work for you. Hope I have answered you correctly.
    Thanks,
    Hasham

  • SQL help - A query to find a delta

    Hi All,
    My case is:
    create table table_test (sample_date date
    ,status varchar2(1)
    ,sum number);
    insert into table_test (sysdate-1,'A',1);
    insert into table_test (sysdate-1,'B',2);
    insert into table_test (sysdate-1,'C',5);
    insert into table_test (sysdate-1,'D',10);
    insert into table_test (sysdate,'A',7);
    insert into table_test (sysdate,'B',2);
    insert into table_test (sysdate,'C',3);
    I need a query that return the delta between today and yesterday:
    status sum
    A 6
    C -2
    D -10
    Thanks!

    WITH t_today AS
         (SELECT status, NVL (SUM, 0) SUM
            FROM table_test
           WHERE sample_date LIKE SYSDATE),
         t_yesterday AS
         (SELECT status, NVL (SUM, 0) SUM
            FROM table_test
           WHERE sample_date LIKE SYSDATE - 1)
    SELECT t_yesterday.status, NVL (t_today.SUM, 0) - t_yesterday.SUM
      FROM t_today RIGHT JOIN t_yesterday ON t_today.status = t_yesterday.status
    S NVL(T_TODAY.SUM,0)-T_YESTERDAY.SUM
    A                                  6
    B                                  0
    C                                 -2
    D                                -10Editted : to correct the query

  • Query to find the user is having access to sql server DB

    Hi,
    Please help me in this.
    Query to find the whether the user is having access to sql server DB.
    Cheers,
    sajith

    TUBBY_ORCL?Select 1 from dual where 'ORACLE' = 'SQL SERVER';
    no rows selected
    Elapsed: 00:00:00.01

Maybe you are looking for

  • How can I "search" for Library Items?

    I am developing a site in flash and have over 800 Library Items. My problem is, I need to edit a portion of a Library Item and cannot find the Library Item, and NO, I did not delete the Library Item because when I go to preview or test the flash docu

  • Audit stored procedure execution details in sql server

    Hi All, how to find stored procedue details and which parameters passed in stored proceduer and out put details in sql server. how can we audit stored procedure details. /Raghavendra

  • Corrupt attachments with damaged filenames

    hi, i'm experiencing problems when receiving certain attachments. the filenames look like this: 'Archive_17?= =?utf-8?Q?0607.zip?=' if i rename it to 'Archive17_0607.zip' i can open the zip, but the ppt-file inside is damaged. i had this problem quit

  • I can't find my installed files in my application folder

    when i try to install something, my computer says it is installed and when i try to find the installed application i can't find it anywhere. It's not in my application folder but it has some stuff in de application support folder. tried to google it

  • HT2186 re:Mac OS X v10.5.8 Build 9L30

    Hi Can anyone inform me if I can upgrade from Mac OS X v10.5.8 Build 9L30 straight to the Lion software or do I have to upgrade to snow leopard first, then lion, the mountain - if so, this will be very costly I guess? Many thanks