1

I am trying to change NULL values of a column in the database to its previous non-null value and save it in the database through a Linq|lambda query, have Entityframework 5.0 with MS-SQl server2012. example:

Time Temperature
11:00 23
12:00 23
13:00 23
14:00 NULL
15:00 23
16:00 NULL
17:00 NULL
18:00 23
19:00 23

to

Time Value
11:00 23
12:00 23
13:00 23
14:00 23
15:00 23
16:00 23
17:00 23
18:00 23
19:00 23

Exampe for SQL is here: (SQL QUERY replace NULL value in a row with a value from the previous known value)

Community
  • 1
  • 1
Muzab
  • 133
  • 1
  • 10
  • I would suggest executing plain SQL query if you want to *update* data in database. Otherwise you need to load all data from table to client, update data in-memory and submit all changes back to database – Sergey Berezovskiy Mar 03 '14 at 10:37

1 Answers1

0

you try to do 2 things at the same time here. - Fetch data - Change data

I would split that up. -First get the data where temperature == null -then iterate over the results and set the values

Patrick
  • 409
  • 2
  • 10
  • I'm not sure I understand your answer correctly, but if you only get the data where temperature is NULL, you don't have enough data to figure out what to set the temperature to. –  Mar 03 '14 at 11:33