Replace null value with previous available value in Row SQL server query

前端 未结 5 1534
我在风中等你
我在风中等你 2021-01-06 15:02

I am looking for building a query to replace null value with previous available values.can somebody help.Here is the table currently looking like

11/30/2015          


        
5条回答
  •  猫巷女王i
    2021-01-06 15:53

    I think this should work, I am assuming the table and column names since you have not provided these, also assuming id is the column based on which you are ordering the rows

     UPDATE table1 T
        SET T.date1 = (
                         SELECT MAX(T2.date)
                           FROM table1 T2
                          WHERE T2.date IS NOT NULL
                            AND T2.id <= T.id
                      )
      WHERE T.date1 IS NULL
    

提交回复
热议问题