Friday, October 2, 2015

UPDATE XML COLUMN DATA


DECLARE @cnt INT 
DECLARE @trace_log_id INT 
DECLARE @message_content NVARCHAR(MAX) 
DECLARE @temp TABLE(Id BIGINT IDENTITY(1,1),trace_log_id int,message_content NVARCHAR(MAX))

INSERT INTO @temp(trace_log_id,message_content)
SELECT trace_log_id,CAST(message_content as NVARCHAR(MAX)) FROM DBR_214438
--select * from @temp
select @cnt=COUNT(*) from @temp
--select @cnt

WHILE(@cnt>0)
BEGIN
      SELECT @trace_log_id=trace_log_id,@message_content=message_content FROM @temp where id=@cnt

      UPDATE @temp
      SET  message_content=REPLACE(message_content,'Monica','******')                                               
      FROM @temp 
      WHERE  trace_log_id=@trace_log_id AND id=@cnt
      UPDATE @temp
      SET  message_content=REPLACE(message_content,'Hermanski','*****')                                           
      FROM @temp 
      WHERE  trace_log_id=@trace_log_id AND id=@cnt

       UPDATE @temp
      SET  message_content=REPLACE(message_content,'1979-11-01T00:00:00','**********')                                            
      FROM @temp 
      WHERE  trace_log_id=@trace_log_id AND id=@cnt
      
                         
      UPDATE t1
      SET t1.message_content=CAST(t2.message_content as XML)
      FROM DBR_214438 t1
      join 
          @temp t2
          ON t1.trace_log_id=@trace_log_id
          AND t2.id=@cnt
     

      SET @cnt=@cnt-1
      --IF(@cnt=0)
      --BREAK;

END 


--drop table  DBR_214438
--select * into DBR_214438 from babji

select * from DBR_214438
--select * from babji

No comments:

Post a Comment