sql - Cross apply to fill down values with multiple columns -


I have a table with some columns I want to fill in the values ​​to change the nulls, but by this extra column is complicated. Here's my sample:

  Date id1 id2 id3 id4 value 1/1/14 a 1 1 1 1.2 1/2/14 a 1 1 1 null 1/8/14 a 1 1 1 2.3 1/1/14 A2 1 1 10.1 1/2/14 A2 1 1 12.3 1/17/14 A2 1 1 NULL 1/18/14 A2 1 1 10.8 1/1/14 A 2 3 1 100.3 1/2/14 A2 3 1 tap 1/6/14 A2 3 1 110.4  

I want to copy down to value value id1 For example, all "A1-1-1" should be isolated from "key-to-1-1", for example, according to what the values ​​have to be copied to me. Required:

  date id1 id2 id3 id4 value 1/1/14 a1 1 1 1.2 1/2/14 a 1 1 1 1.2 1 / 8 / 14A1 1 1 2.3 1/1/14 A2 1 1 10.1 1/2/14 A2 1 1 12.3 1/17/14 A2 1 1 12.3 1/18/14 A2 1 1 10.8 1 / 1 / 14A 2 3 1 100.3 1/2/14 A2 3 1 100.3 1/6/14 A2 3 1 110.4 I  CROSS APPLY  
  announcement @ test table (date DATETIME, Include ID1 VARCHAR (1), ID2INT, ID3INT, ID4INT, Well Float) @ Test Value ('2014-01-01', 'A', '1', ' 1 ',' 1.2 '), (' 2014-01-02 ',' A ',' 1 ',' 1 ',' 1 ', null), (' 2014-01-08 ',' A ',' 1 ',' 1 ',' 1 ',' 2.3 '), (' 2014-01-01 ',' A ',' 2 ',' 1 ',' 1 ', '10.1') ('2014-01-02', 'A', '2', '1', '1', '12.3 '), 2014-01-17,' A ',' 2 ',' 1 ',' 1 ', null), (' 2014-01-18 ',' A ',' 2 ',' 1 ',' 1 ', '10.8'), ('2014-01-01', 'A' , '2', '3', '1', '100.3'), ('2014-01-02', 'A', '2', '3', '1', NULL) 01-06 ',' A ',' 2 ',' 3 ',' 1 ',' 110.4 '); SELECT * FROM @test;  

You can apply to:

  Select T., Colles (T. Value, TRPR.) @ Test T apply to External Applicability (from @ Test T2, select the top 1 value where T.ID1 = T .ID 1 and T2 is not a tap sequence by id2 = t.id2 and t2.id3 = t.id3 and t2.id4 = t.id4 and t2.date & lt; t.date and t2.value t2.date) Tprev;  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -