Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using Find and Replace with Regular Expressions to match one word and exclude another Expand / Collapse
Author
Message
Posted Wednesday, December 12, 2012 11:36 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 6:38 AM
Points: 39, Visits: 875
I am using Find and Replace in SSMS to search for any line in my T-SQL code that contains a CREATE but does not include a following DBO. (not case-sensitve) to qualify the object being created. I am able to query all occurrences where CREATE and DBO exist, but have not had much luck trying to exclude where DBO did not follow the CREATE somewhere on the line.

For example, this below code finds all CREATE followed by a DBO on the line:

<CREATE(([^:a]+[:a]+)^1|([^:a]+[:a]+)^2|([^:a]+[:a]+)^3)[^:a]+DBO>

I just do not have the Regex mettle to find where a DBO does not trail the CREATE.

Any help would be greatly appreciated, as I am a little stuck on this one.

Thank you,
Tom






Post #1395826
Posted Wednesday, December 12, 2012 11:58 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:59 AM
Points: 11,941, Visits: 10,975
like '%create%dbo%'

Not really sure what you are looking for. Also if you only the dbo schema why does it matter much if the object is not fully qualified?


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1395831
Posted Wednesday, December 12, 2012 12:10 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 6:38 AM
Points: 39, Visits: 875
Hello and thanks for the quick reply. I am trying to use the Regular Expressions feature in Find and Replace of the SSMS UI to search my text file that contains our T-SQL code.


Post #1395834
Posted Wednesday, December 12, 2012 12:23 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: 2 days ago @ 1:34 PM
Points: 15,442, Visits: 9,588
I don't think that's a regex issue. Wouldn't you just use a find with a "and not" in it? Find anything with CREATE, and not with the regex you already wrote?

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1395839
Posted Wednesday, December 12, 2012 3:52 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 6:38 AM
Points: 39, Visits: 875
I am using the Find and Replace dialog from within SSMS. I have a large text file (> 100K lines) that includes a delta of all our change scripts.


Post #1395910
Posted Thursday, December 13, 2012 7:43 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:59 AM
Points: 11,941, Visits: 10,975
I still say that if you are only looking for dbo that it seems unnecessary. If you have only one schema everything will be created there anyway. Unless you are just trying to figure out how to make the regex work and you can tweak it slightly to check for each schema. I have never had great success with the regex tool in the search dialog. Maybe it is my inability to create complex regex.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1396195
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse