Search and Replace

analysis
Feb 19, 20082 mins

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 s

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

GO

Replacing ‘= 63’ with ‘

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

Watch my free SQL Server Tutorials at:

https://MidnightDBA.ITBookworm.com Read my book reviews at:

www.ITBookworm.com

Blog Author of:

DBA Rant – https://dbarant.blogspot.com