954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HELP to use Regex in sql

Hi all,

I want to know how to assin a return value to a variable when calling a regex function.
it always returns a bit type of value(its ok). i want that bit type of value tobe cheked whether it is '0' or '1'

this is my C# code in case if u need

namespace SearchBooksLibrary
{
    public partial class SqlRegularExpressions
    {

       
        public static int Like(string text, string pattern)
        {
            Match match = Regex.Match(text, pattern);
            if (match.Value != String.Empty)
                return 1;
            else
                return 0;
        }
    }
}


this is my assembly.

CREATE ASSEMBLY SqlRegularExpressions1 
from 'C:\Users\BJ\Documents\Visual Studio 2008\Projects\Project1\SearchBooksLibrary\SearchBooksLibrary\bin\Debug\SearchBooksLibrary.dll' 
WITH PERMISSION_SET = SAFE

this is my function

CREATE function RegExpLike(@Text nvarchar(max), @Pattern nvarchar(255)) RETURNS bit 
AS EXTERNAL NAME SqlRegularExpressions1.[SearchBooksLibrary.SqlRegularExpressions].[Like]


this is what i want to do which doesnt work

declare @tt nvarchar(max)
set @tt='i love sql but not the other'
declare @ttT nvarchar(max)
set @ttT='(\w*sql\w*)*(server\w*)'
declare @flag bit
@flag=select dbo.RegExpLike(@tt,@ttT )--this line does not work it says Incorrect syntax near '@flag'.

plz help me

coroll
Junior Poster in Training
75 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Try

select @flag=dbo.RegExpLike(@tt,@ttT)
adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 

thanks it worked

coroll
Junior Poster in Training
75 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You