Solved

Regex replace in SSMS

Posted on 2013-06-10
2
333 Views
Last Modified: 2013-06-13
In SSMS I would like to include square brackets for schema. If dbo is schema name is dbo otherwise the schema name is xxxx.yyyy

dbo.spSomeName should be replaced as [dbo].[spSomeName]
dbo.tSomeName   should be replaced  as  [dbo].[tSomeName]
MyDB.AnySchema.spSomeName should be replaced  as  [MyDB.AnySchema].[spSomeName]
MyDB.AnySchema.tSomeName should be replaced  as  [MyDB.AnySchema].[tSomeName]

How to achieve this using Regex replace? Please suggest
0
Comment
Question by:Easwaran Paramasivam
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39236409
Regular expressions in SSMS are really horrible and non-standard, even by Microsoft's track record!

Documentation is available here: http://msdn.microsoft.com/en-us/library/ms174214%28v=sql.90%29.aspx

My forte is Regular Expressions in general, and I'm not a Microsoft programmer, so I can't test this for you, however I think this might work for you:

Match:
{([a-zA-Z0-9_]+\.)*[a-zA-Z0-9_]+}\.{[a-zA-Z0-9_]+}
Replace with:
[\1].[\2]

It will also match cases like:
otherstuff.morestuff.MyDB.AnySchema.SomeName

If that's a problem, we can probably alter the pattern to fix that.

Let me know how it goes.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39236427
This might be slightly better (ie I think it fixes the problem I previously pointed out), and uses the same replacement:

Match:
{([a-zA-Z0-9_]+\.|)[a-zA-Z0-9_]+}\.{[a-zA-Z0-9_]+}
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now