Author |
Topic |
xclaim
Starting Member
8 Posts |
Posted - 2014-05-13 : 08:22:11
|
INPUT datano. data1 data12 3 4 data25 6 data37 8 9 data410 data5 OUTPUT neededno. data1 data12 data13 data14 data25 data26 data37 data38 data39 data410 data5 Basically all the nulls/blanks in the input data column need to be filled with data from the previous rowthanks in advance. |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-05-13 : 09:23:10
|
[code];with aCTEAS (select 1 no, 'data1' data union all select 2,null union all select 3,null union all select 4,'data2' union all select 5, null union all select 6,'data3' union all select 7,null union all select 8, null union all select 9,'data4' union all select 10,'data5' )select A.no,B.data from aCTE AS A outer apply ( select top 1 B.data from aCTE as B WHERE a.NO >= b.no AND B.data IS NOT NULL ORDER BY B.no DESC )B[/code]output[code]no data1 data12 data13 data14 data25 data26 data37 data38 data39 data410 data5[/code]sabinWeb MCP |
|
|
xclaim
Starting Member
8 Posts |
Posted - 2014-05-13 : 10:04:28
|
thanks stepsoni enhanced it a bitSELECT 1 no, 'data1'data , null data_newUNION ALL SELECT 2, NULL , nullUNION ALL SELECT 3, NULL , nullUNION ALL SELECT 4, 'data2' , 'data6'UNION ALL SELECT 5, NULL , nullUNION ALL SELECT 6, 'data3' , nullUNION ALL SELECT 7, NULL , nullUNION ALL SELECT 8, NULL , 'data7'UNION ALL SELECT 9, 'data4' , nullUNION ALL SELECT 10, 'data5' , null input now isno data data_new1 data1 2 3 4 data2 data65 6 data3 7 8 data79 data4 10 data5 output should beno data data_new1 data1 2 data1 3 data1 4 data2 data65 data2 data66 data3 data67 data3 data68 data3 data79 data4 data710 data5 data7 nulls are fine as wellthanks much |
|
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-05-14 : 01:06:28
|
[code];with aCTEAS (SELECT 1 no, 'data1'data , null data_new UNION ALL SELECT 2, NULL , null UNION ALL SELECT 3, NULL , null UNION ALL SELECT 4, 'data2' , 'data6' UNION ALL SELECT 5, NULL , null UNION ALL SELECT 6, 'data3' , null UNION ALL SELECT 7, NULL , null UNION ALL SELECT 8, NULL , 'data7' UNION ALL SELECT 9, 'data4' , null UNION ALL SELECT 10, 'data5' , null )SELECT A.no ,B.data ,C.data_newFROM aCTE as A outer apply ( select top 1 B.data from aCTE as B WHERE a.NO >= b.no AND B.data IS NOT NULL ORDER BY B.no DESC )B outer apply ( select top 1 B.data_new from aCTE as B WHERE a.NO >= b.no AND B.data_new IS NOT NULL ORDER BY B.no DESC )C[/code]output:[code]no data data_new1 data1 NULL2 data1 NULL3 data1 NULL4 data2 data65 data2 data66 data3 data67 data3 data68 data3 data79 data4 data710 data5 data7[/code]sabinWeb MCP |
|
|
|
|
|