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 |
GLupien
Starting Member
2 Posts |
Posted - 2015-01-17 : 06:47:25
|
I have a pivot query returning data ordered by a timestamp. In any give second only a few of the columns will have data, the remaining columns are NULL. I would like to default the NULL data values to the previous NON NULL value by timestamp.Current Pivot Table:Time RowA RowB RowC12:15:12 NULL NULL 5012:15:11 97 NULL NULL12:15:10 98 25 5112:15:06 101 NULL 5012:15:05 100 NULL NULLWhat should be returned:Time RowA RowB RowC12:15:12 97 25 5012:15:11 97 25 5112:15:10 98 25 5112:15:06 101 NULL 5012:15:05 100 NULL NULLI know that I can do this user a cursor and handling the output is code, but I would prefer to do this in a single set based query.Regards,GrantRegards,Grant F. Lupien |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-01-17 : 11:10:24
|
If you're running sql server 2012 or 2014, read up on the LAG function. You can use it to do just what you want. |
|
|
|
|
|