1: /*
2: *
3: * Search & Replace
4: * Use Ctrl+Shift+M to replace template values
5: *
6: */
7:
8: set xact_abort on
9: begin tran
10:
11: declare @otxt varchar(1000)
12: set @otxt = '<string1, text, text to be replaced>'
13:
14: declare @ntxt varchar(1000)
15: set @ntxt = '<string2, text, replacing text>'
16:
17: declare @txtlen int
18: set @txtlen = len(@otxt)
19:
20: declare @ptr binary(16)
21: declare @pos int
22: declare @<string3, text, name of Unique Row ID> int
23:
24: declare curs cursor local fast_forward
25: for
26: select
27: <string3, text, name of Unique Row ID>,
28: textptr(<field_name, sysname, target text field>),
29: charindex(@otxt, <field_name, sysname, target text field>)-1
30: from
31: <table_name, sysname, target table>
32: where
33: <field_name, sysname, target text field>
34: like
35: '%' + @otxt +'%'
36:
37: open curs
38:
39: fetch next from curs into @<string3, text, name of Unique Row ID>, @ptr, @pos
40:
41: while @@fetch_status = 0
42: begin
43: print 'Text found in row id=' + cast(@<string3, text, name of Unique Row ID> as varchar) + ' at pos=' + cast(@pos as varchar)
44:
45: updatetext <table_name, sysname, target table> .<field_name, sysname, target text field> @ptr @pos @txtlen @ntxt
46:
47: fetch next from curs into @<string3, text, name of Unique Row ID>, @ptr, @pos
48: end
49:
50: close curs
51: deallocate curs
52:
53: commit tran