Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 row by row comparision

Author  Topic 

sushil
Starting Member

11 Posts

Posted - 2010-05-19 : 19:25:31
I need a logic which can transform the following records in a table A
Years Price
2000 55
2001 55
2002 60
2003 65
2004 70
2005 75
2006 75
2007 75
2008 80
2009 90
2010 100

to

Years Price
2000 55
2002 60
2003 65
2004 70
2005 75
2008 80
2009 90
2010 100

It is basically not showing the reocords for next year if price is same.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-20 : 02:35:53
If price is never falling:
select
min(years) as years,
price
from @test
group by price
order by years



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-20 : 03:34:55
if the Years is continuous,

select t1.Years, t1.Price
from table1 t1
left join table1 t2 on t1.Years = t2.Years + 1
where t1.Price <> t2.Price
or t2.Price is null



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -