sql - Update table using stored procedure -
we getting data excel source , keeping in temp table , updating target table using temp table stored procedure.i facing problems 'comments' column in target table if new comment comes in should prepend existing comment. riddle here target table column combination of input parameters , fields along comments.eg:
[target.comments] = '[manager ' + @getdateparameter +'' + uploaded + '] ' +temp.comments + '' + target.comments.
when new record comes in today,
comment = [manager1 may_9_2013 uploader1] robert in canada
if run again in day , there no update (it should check existing comment) in comment
comment = [manager1 may_9_2013 uploader1] robert in canada
if there update in comment on may 15 th should be
comment = [manager1 may_15_2013 uploader1] robert moved away canada , in us.[manager1 may_9_2013 uploader1] robert in canada
how achieve this? thanks.
your don't provide real info write code (are looping, inserting in single statement, etc), try this:
update y set yourcomment=t.newvalue+isnull('; '+y.yourcomment,'') yourtable y inner join yourtemptable t on y.pk=t.pk t.newvalue not null
i coded place "; " between comments, can remove if not necessary. replace "t.newvalue" string concatenation forms new comment.
this schema problem. should create comments table, split out different values own columns, , have 1 row per comment. @ point, insert , no updates or concatenations. can use view or in application processing combine them user presentation.
Comments
Post a Comment