sql server - copy/update records of certain columns of one row to all other rows of the same table based on ID -
i have mssql 2012 table first row of sheetname column contains values customer, project , plant, based on id.
now want "copy" records of 3 columns to other rows id same , sheetname = "sheet 1".
here's fiddle input , desired output table.
with "copy" mean don't want update actual table, instead want create view populate columns records.
at moment have no idea how can there can me out. doubt great performance view. procedure better job guess.
thank you.
update i've updated fiddle task: added comment column if record null previous comment value should used.
first of did put same id row in input table, assumed error. , confess did not explication, think suffer bad design, no primary key, , 1 table when break table 2 different one. there humble solution, again not sure want it.
select myinputtable.id, myinputtable.row, j.customer,j.project, j.plant,myinputtable.sheetname myinputtable left join myinputtable j on (myinputtable.id=j.id , j.customer not null) the join allows add column in result table left join have @ least 1 row each row of myinputtable, condition after on, want add row of j if id same , if there customer name.
Comments
Post a Comment