RegEx in TSQL

phinix

Registered User.
Local time
Today, 11:35
Joined
Jun 17, 2010
Messages
130
Hi guys, I have this function in VB that I used in Access to replace all non-alphanumeric characters, including spaces and anything in brackets.

Code:
Public Function charOnly3(inputString As String) As String
Dim RE As Object

Set RE = CreateObject("vbscript.regexp")

RE.Pattern = "\([^)]+\)|[^\w]|_"

RE.Global = True
charOnly3 = RE.Replace(inputString, "")

Set RE = Nothing

End Function
Now, I moved to SQL server and I'm writing scripts to do same thing.

How can I use RegEx in TSQL?
Only thing I will do is that function.
 
Last edited:
Welcome to the Club of converting VBA to T-SQL.
Found an interesting article about creating a UDF (User Defined Function in T-SQL) using the reference in your code.
http://blogs.msdn.com/b/khen1234/archive/2005/05/11/416392.aspx

Maybe this can get things started.

If you have questions about it, I often use this forum:
http://www.sqlservercentral.com/Forums/Forum1292-1.aspx
This is the SQL Server Newbie forum.
Often, they will point me in a direction. Other times, they do something else less helpful. Some of them are extremely anti-UDF.
Just realize, some of these very intellignt people manage tera-bytes of data in a single transaction. From that point of view a UDF is probably to be avoided.
A small SQL Server DB is under 1,000 GB.
In the newbie forum, I find it useful to disclose the tiny sizes of my under 1 GB databases. Even a less efficient written UDF against 200,000 records can appear lightning fast against a function call in Access using a linked table to the same 200,000 records.

I did find this interesing. Look at the UDF link and ask more questions here too.
The ("vbscript.regexp") is new to me, but looks interesting.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom