nix, shell, perl, php, mysql and mac os x tips and tricks

Thursday, March 30, 2006

Search and replace in MSSQL (specifically in TEXT field)

Just use Ctrl+Shft+M in Query Analyzer to replace the parameters. Then hit "play" in query analyzer til u don't get any more hits.
01./*
02.*
03.* Search & Replace
04.*
05.* Use Ctrl+Shift+M to replace template values
06.*
07.*/
08. 
09.set xact_abort on
10.begin tran
11. 
12.declare @otxt varchar(1000)
13.set @otxt = ''
14. 
15.declare @ntxt varchar(1000)
16.set @ntxt = ''
17. 
18.declare @txtlen int
19.set @txtlen = len(@otxt)
20. 
21.declare @ptr binary(16)
22.declare @pos int
23.declare @id int
24. 
25.declare curs cursor local fast_forward
26.for
27.select
28. id,
29. textptr(),
30. charindex(@otxt, )-1
31.from
32.  
33.where
34.  
35.like
36. '%' + @otxt +'%'
37. 
38.open curs
39. 
40.fetch next from curs into @id, @ptr, @pos
41. 
42.while @@fetch_status = 0
43.begin
44. print 'Text found in row id=' + cast(@id as varchar) + ' at pos=' + cast(@pos as varchar)
45.  
46. updatetext  . @ptr @pos @txtlen @ntxt
47. 
48. fetch next from curs into @id, @ptr, @pos
49.end
50. 
51.close curs
52.deallocate curs
53. 
54.commit tran

Wednesday, March 1, 2006

Workaround for "argument list too long" error on 'nix

1.find /home/rory/backup/Mail/outbox/ -type f -name '*' -exec cp {} /home/rory/Mail/outbox/ \;