0

What is the regular expression pattern that enables every input besides characters? So far this is what i have -

CREATE PROCEDURE Paging_Movies
@alphaChar char(1)
AS
if @alphaChar = '#'
select * from Movies where movies like '[0-9]%'
else
select * from Movies where movies like @alphaChar + '%'
2
  • 1
    Do you mean you want only numbers? Or all characters that aren't a-z? Commented Jun 15, 2011 at 23:23
  • this is for sql server 2008 r2, and yes all characters that aren't a-z Commented Jun 15, 2011 at 23:37

2 Answers 2

2

If you want true regular expression pattern matching you will need to roll your own CLR UDF. This link goes over how to do that:

http://msdn.microsoft.com/en-us/magazine/cc163473.aspx

Keep in mind that you can only do this in SQL Server 2005 or higher.

If you just want non-alpha you can do this:

'([^a-z])'

Here is the documentation for SQL Server like:

http://msdn.microsoft.com/en-us/library/ms179859.aspx

Sign up to request clarification or add additional context in comments.

Comments

2

SQL Server 2008 R2 has some regular expression functions built-in.

Here's a link explaining how to extract them and use them in your own database.

2 Comments

Very cool, didn't know about that. So you are still creating a CLR function right? Just from a Microsoft assembly instead of your own?
@Abe Miessler: I haven't used it personally, but yes - it just saves you rolling your own as there are already some in there!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.