I’ll try to avoid describing the background here. I now have a query result (not a table) which contains rows like this:
ID SP1 SP2 SP3 SP4 SP5 SP6 SP7 SP8 1 null null 2500 1400 700 null null null
There may be leading and/or trailing null values around a section of non-null values (which represents a decreasing process actually). And what I want is like this:
ID SP1 SP2 SP3 SP4 SP5 SP6 SP7 SP8 1 2500 2500 2500 1400 700 0 0 0
That means, to replace leading nulls with the first non-null value, and trailing nulls with 0.
Please advise. I’m working on SQL Server 2000.
COALESCE takes a number of expressions, and returns the first non-null value.