Anonymous - 2012-11-16

If you look at the below insert statement, I am escaping the parenthesis with two backslashes to insert the record in the database and that works fine. After that, when I update the same record in that field, when I change the value from 22 to 23 with the two backslashes, it no longer inserts the \( in the db. So what seems to be the issue? Any help would be very much appreciated.
DEVPNCOMS..1> insert into custom.maintenance (KeyField, Device, sModeType, StartTime, EndTime, Flag, EnteredBy, Reason, DevComp, sModeScope, MessageText, LOB) values('Device_serverx_MessageText_test\'s datastore1_\\(22\\)_1353107520_1353108420', ‘serverx’, 'Device', 1353107520, 1353108420, 1, 'gnangia','test','Server','MessageText','test\'s datastore1_\\(22\\)','XXXX');
DEVPNCOMS..1> go
DEVPNCOMS..1> select MessageText from custom.maintenance
DEVPNCOMS..2> go

test's datastore1_\(22\)

DEVPNCOMS..1> update custom.maintenance set MessageText='test\'s datastore1_\\(23\\)'
DEVPNCOMS..2> go
DEVPNCOMS..1> select MessageText from custom.maintenance
DEVPNCOMS..2> go

test's datastore1_(23)

I did some further testing and found that if I use 4 backslashes before the parenthesis, it inserts a single backslash - same as the initial insert - but this is only true if I have a single quote in the value prior to the parenthesis. If there is no single quote or the single quote is after the parenthesis, I only need two backslashes, which seem to be very inconsistent.