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 |
|
matta0990
Starting Member
44 Posts |
Posted - 2011-12-01 : 03:58:05
|
| Hi,I've got a list fo dataVALUE:12345670008900010etc...I'm trying to get my sql to use the last known value if value = 0so the list would like liek soVALUE12345677778999910any ideas? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-01 : 04:04:51
|
is there another column in the table that can determine the sequence / ordering of the records ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
matta0990
Starting Member
44 Posts |
Posted - 2011-12-01 : 04:09:21
|
| yes sorry itsPeriod_Idday1day2day3day4day5day6etc.... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-01 : 04:15:01
|
[code]select Period_Id, t.Value, Value = coalesce(nullif(t.Value, 0), p.Value)from yourtable t cross apply ( select top 1 x.Value from yourtable x where x.Value <> 0 and x.Period_Id <= t.Period_Id order by x.Period_Id desc ) porder by Period_Id[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|