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 2000 Forums
 SQL Server Development (2000)
 NULL Values

Author  Topic 

daidaluus
Yak Posting Veteran

73 Posts

Posted - 2010-04-20 : 07:42:25
I have the following data

id value
-- -----
1 10
2 NULL
3 NULL
4 8
5 NULL
6 12
7 NULL
8 NULL
9 NULL

How can i get the following result?

id value
-- -----
1 10
2 10
3 10
4 8
5 8
6 12
7 12
8 12
9 12

or how can I update the table to have these values?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-20 : 08:57:28
[code]
select d.id,
isnull( d.value,
(select top 1 value from data x where x.id < d.id and x.value is not null order by id desc)
)
from data d
[/code]


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

Go to Top of Page
   

- Advertisement -