merged cells in excel
when import data excel ms sql, got following rows in db.in excel row2 row4: field1 merged , row5 & rows6:field1 merged. now, want replace null values row2 field1 value in row3, row4 field1, similaryly row4 field1 value in row6 field.
row1 - field1 field2 field3
row2- abc b c
row3- null d e
row4- null f g
row5- def i j
row6- null k l
finally should this...
row1 - field1 field2 field3
row2- abc b c
row3- abc d e
row4- abc f g
row5- def i j
row6- def k l
i suggest use sql - cursor to process these records, can't sort them because break sequence, cursor can process them row row.
here's code testing data.
declare @rowdata table ( field1 varchar(50), field2 varchar(50), field3 varchar(50) ) insert @rowdata values ('abc','b','c'), (null,'d','e'), (null,'f','g'), ('def','i','j'), (null,'k','l') select * @rowdata declare @field varchar(50) = null declare @nonfield varchar(50) = null declare field_cursor cursor select field1 @rowdata open field_cursor; fetch next field_cursor @field; set @nonfield = @field while @@fetch_status = 0 begin if @field null update @rowdata set field1 = @nonfield current of field_cursor -- update data @ current row non-null field value fetch next field_cursor @field; if @field not null set @nonfield = @field end; close field_cursor; deallocate field_cursor; select * @rowdata
please vote if it's helpful , mark answer!
SQL Server > SQL Server Integration Services
Comments
Post a Comment