Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting changed data

Status
Not open for further replies.

Cobby1812

IS-IT--Management
Joined
Jun 22, 2006
Messages
58
Location
GB
Hi All,

In my database I need to know when a value has changed i.e (below)....on from 02/04/2013 till 24/04/2013 the value was 60000.00 then it went to 5.00. Whats the easiest way to find this value........

2013-04-02 00:00:00.000 0 60000.00
2013-04-08 00:00:00.000 0 60000.00
2013-04-12 00:00:00.000 0 60000.00
2013-04-15 00:00:00.000 0 60000.00
2013-04-24 00:00:00.000 0 5.00
 
Hi,

Try something like this:

Code:
with CTE_RN as
(
    select 
        *,
        ROW_NUMBER() OVER(ORDER BY MyDate) as RN 
    from MyTable
)

select
    *
from CTE_RN as c
inner join CTE_RN as p
    on p.RN = c.RN - 1
where 
    c.MyValue <> p.MyValue

Hope this helps.

[URL unfurl="true"]http://www.imoveisemexposicao.com.br/imobiliarias-em-guarulhos[/url]
 
Thanks imex...will give it a whirl.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top