Free Newsletters

   All InfoWorld Newsletters
Database Underground | Sean McCown » Search and Replace

February 19, 2008 | Comments: (0)

Search and Replace

In writing some code this morning I found it necessary to make some major changes that involved search and replace in SQL Mgmt Studio. I was a little disappointed in the ability of both the SQL tools and Visual Studio to perform rich replace routines.

Here's a simple example of what I was trying to do:

Create View myView
as
Select * from myTable where col1 = 63


I had a couple hundred of these statements in the script and they needed to be changed to:

Create View myView
as
Select * from myTable where col1 < 50
GO


Replacing '= 63' with '< 50' is the easy part.
But try putting that 'GO' statement on the next line between all of them. If there's a way to do it in the tool it's not apparent.

This is why I always keep a version of PrimalScript handy. It has a search/replace util that I haven't seen matched anywhere else. And I wasn't even sure if it would do what I wanted, but it did.
What can I say. I still love this tool. Even though I don't use it for much of my scripting anymore (I just don't do that kind of scripting at my current job), I always have it loaded on my box for emergencies like this.
There are some things I'd like to see PrimalScript's search/replace do, and maybe I'll shoot them a note about some of them. And no, they don't pay me for stuff like this. I actually just love this tool.

Here's a small Camtasia I put together to show you how it works.
SearchReplace.wmv

Posted by Sean McCown on February 19, 2008 10:44 AM


RATE THIS ARTICLE:





 

  •  
  • COMMENTS




How about using Regular Expressions within SSMS find & replace?
Find what: col1 = {[0-9]*}
Replace with: col2 < \1 \nGO
would do the trick for the example you cite

Posted by: moff at March 19, 2008 04:06 AM

Technology White Papers

 

InfoWorld Technology Marketplace

» Technology White Papers Library

Technology White Papers by Topic

Technology White Papers E-mail Alert

Find out when the latest white paper is available:
 
 
» BUY A LINK NOW

Sponsored Technology Links