sql - Insert new row if value present in column -
i need check if column value exists record, , if insert duplicate of record, 1 of fields updated.
the fields inccodes table are chars:
incomecode, description, location, costcentre, newincomecode
i have sql command updates of incomecodes newincomecode , clears newincomecode column present:
update inccodes set incomecode = newincomecode ,newincomecode = '' newincomecode <> '' , location = location1
however need command same thing except instead of updating incomecode field, creates duplicate record incomecode updated newincomecode field. pseudo sql:
insert inccodes values (select newincomecode ,description ,location ,costcentre ,null inccodes newincomecode <> '')
any advice appreciated. can see similar questions insert based on criteria nothing need.
thanks in advance.
insert ignore inccodes (incomecode, description, location, costcentre, newincomecode) select newincomecode, description, location, costcentre, '' inccodes newincomecode <> '' , location = location1 ;
Comments
Post a Comment