I have done some SMO-programming in order to convert all varchar, char and text fields to nvarchar, nchar and nvarchar(max) in a database. I'm also using SMO and regular expressions to do the same thing in all stored procedures in the database. Replacing variables and parameters is no problem, I have working regular expressions for matching those.
But I'm having some problems with string matchine - I need to replace all 'some string' with N'some string' in all stored procedures. The regex I'm using for that string matching right now is: (['])(?:(?!\1)[^'']|''.|''''.)*\1
But that's not working perfectly. I'm using it now, and manually going through a text-file with all 1600 stored procedures, correcting where the regex hasn't made a correct match. I'm almost finished, but it struck me that I can't be the only who ever did this exercise...How would you do this? Would you say using SMO and Regex is the way to go? If so, does anyone have a regex that correctly matches SQL Server strings?
asked Jul 04, 2010 at 12:04 AM in Default
The regex you want is the following:
Let me know if that works for you, but I've tested it with a few edge cases and it seems OK... By the way, if you don't use it, I heartily recommend [Expresso].: http://www.ultrapico.com/Expresso.htm
answered Jul 04, 2010 at 02:00 PM
Matt Whitfield ♦♦