'SQL Server NULLS: duplicate last known value in table
I need some advice.
I have a column with nulls in a field at a particular time period.
Name Date
----- -----
Cat 1/1/2012
Dog 1/2/2012
Fish 1/3/2012
NULL 1/4/2012
Goat 1/5/2012
NULL 1/6/2012
Sheep 1/7/2012
In the example above, how would I write a SQL statement to select the last known value for column Name whenever there is a null value in the column?
For instance I'd like the table to look like this:
Name Date
----- -----
Cat 1/1/2012
Dog 1/2/2012
Fish 1/3/2012
Fish 1/4/2012
Goat 1/5/2012
Goat 1/6/2012
Sheep 1/7/2012
Would this pseudo-code work?
Select
isnull(Name, "Select Name from Table where Date = GetDate() - 1")
,Date
From Table
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
