June 7, 2012 at 1:14 pm
I am creating a small project to read match regex from sql,
.cs file
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Text.RegularExpressions;
public partial class RegExBase
{
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static bool RegexSHIP(string matchString, string pattern)
{
Regex r1 = new Regex(pattern.TrimEnd(null));
return Regex.Match(matchString.TrimEnd(null), pattern.TrimEnd(null)).Success;
}
};
Test.sql
select * from [databasename].[dbo].tablename as P, [databasename].[dbo].tablename as S
where P.UserID = 'Rep'
and S.UserID = P.UserID
and dbo.RegexSHIP('T_SHIP_123456.txt', S.Pattern) = 1
I have enable clr, created function but still getting the attach error and help to solve that.
Thanks
June 7, 2012 at 1:19 pm
the error message is related to debugging.
do you really need to debug the CLR?
why not just deploy the project, then test it in q window for known pattern/values?
Lowell
June 7, 2012 at 2:14 pm
do you really need to debug the CLR? No
All I want is to test it.
why not just deploy the project, then test it in q window for known pattern/values?
everything run fine except I don't get any output.
June 7, 2012 at 3:09 pm
I think I solved my issue, it was from my data it needed some clean up
June 8, 2012 at 7:17 am
Slightly off subject, it's been reported that some forms of Regex CLR are quite slow. If it does turn out to be one of the slow ones, it won't look slow on just a couple of rows but could take quite some time if you're batch processing several thousand rows.
To be sure, I'm not in any way shape or form saying to avoid CLRs. I'm saying the same as I would for any type of code where there was a known issue including T-SQL and to simply be aware of it.
The question that I would have is what are you doing in RegEx that a more simple LIKE or other pattern matching in T-SQL can't do for you? The reason why I'm asking that is because if you are using Regex to replace the simple pattern matching that you can do in T-SQL, there's a very high probability that functionality will be a fair bit slower than the equivalent T-SQL code.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply