SQL - Search and Replace

0

Please login or register to vote for this query.

(click on this box to dismiss)

http://stackoverflow.com/questions/12446027/search-and-replace-serialized-db-dump/12446151#12446151

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @t TABLE(
  s VARCHAR(50)
);
INSERT INTO @t VALUES('s:22:\"http://somedomain.com/\"'),
              ('s:26:\"http://somedomain.com/abc/\" '),
              ('s:29:\"http://somedomain.com/abcdef/\"');
              
UPDATE @t 
SET s = REPLACE(REPLACE(s, 'somedomain', 'someOtherdomain'), CONVERT(INT, SUBSTRING(s, CHARINDEX(':', s) + 1, 2)),
CONVERT(INT, SUBSTRING(s, CHARINDEX(':', s) + 1, 2)) +5);


SELECT * FROM @t;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results