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.
Author |
Topic |
micnie_2020
Posting Yak Master
232 Posts |
Posted - 2012-12-20 : 20:45:27
|
Hi All,How to shift the price value if the ID having Datt 2012/04 else remain same.Before:ID Datt Amt Price1 2012/01 3 501 2012/02 3 01 2012/03 3 01 2012/04 3 02 2011/01 5 902 2011/02 5 0After:ID Datt Amt Price1 2012/01 3 01 2012/02 3 01 2012/03 3 01 2012/04 3 502 2011/01 5 902 2011/02 5 0Please advise.Thank you.Regards,Micheale |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-12-20 : 20:51:04
|
Your question is not clear. |
|
|
micnie_2020
Posting Yak Master
232 Posts |
Posted - 2012-12-20 : 20:56:32
|
Hi,To explain further,eg: i need all the group ID which having Datt 2012/04, the previous Price value will shift to Datt 2012/04ID Datt Price1 2012/04 50and the previous record price will zerolizeID Datt Price1 2012/01 0For ID 2, there is no Datt 2012/04. Mean the value remain as Current without changing the price value.Hope i make my question clear.Thank you.Regards,Micheale |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-12-20 : 21:09:00
|
[code]Select T.ID,T.Date,T.Amt,Case When T.Date = '2012/04' then P.Price Else T.Price End as Pricefrom Table Tleft join(Select ID,MIN(Date) MinDate,MIN(Price) Pricefrom TableGroup by ID)P on P.ID = T.ID and T.Date = P.MinDate[/code] |
|
|
|
|
|