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