473,247 Members | 2,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,247 software developers and data experts.

SELECT and regular expression

Hi,

I'm not a big friend of MSSQL, but I have to do one query I've done for
mySQL.
But I don't know how...

I have to select 'user' from 'db' where first letter is E or N, second is B
or 0 and after that there are 6 or 7 digits I know.
How can I do that?

In mySQL it would be something like:

SELECT * FROM `table` WHERE `account` regexp '^[EN][B0]123456$' ORDER BY
`Id`;
Thanks in advance,
Martin
Apr 24 '06 #1
10 73739
where ( account like 'EB%
or account like 'NB%' )
and ( account like 'E0%
or account like 'N0%' )
and len( account ) between 6 and 7

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Martin Lukasik" <ma****@milea.pl.i.hate.this.spam> wrote in message
news:68**************************@ZOO.CO.UK...
Hi,

I'm not a big friend of MSSQL, but I have to do one query I've done for
mySQL.
But I don't know how...

I have to select 'user' from 'db' where first letter is E or N, second is
B or 0 and after that there are 6 or 7 digits I know.
How can I do that?

In mySQL it would be something like:

SELECT * FROM `table` WHERE `account` regexp '^[EN][B0]123456$' ORDER BY
`Id`;
Thanks in advance,
Martin

Apr 24 '06 #2

"Tony Rogerson" <to**********@sqlserverfaq.com> wrote in message
news:e2*******************@news.demon.co.uk...
where ( account like 'EB%
or account like 'NB%' )
and ( account like 'E0%
or account like 'N0%' )
and len( account ) between 6 and 7


Thank you,

Is there any easier way?
What if first characters are A, D, C, 4, X, Z, Y? It's not really nice to
type every permutation.
There must be some regular expression...

Martin
Apr 24 '06 #3
where account like '[EN][BO][0-9][0-9][0-9][0-9][0-9][0-9]'
or account like '[EN][BO][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'

Apr 24 '06 #4
On Mon, 24 Apr 2006 16:37:44 +0100, Martin Lukasik wrote:
Hi,

I'm not a big friend of MSSQL, but I have to do one query I've done for
mySQL.
But I don't know how... (snip)In mySQL it would be something like:

SELECT * FROM `table` WHERE `account` regexp '^[EN][B0]123456$' ORDER BY
`Id`;


Hi Martin,

Try

SELECT * -- Use column list instead!!
FROM table
WHERE account LIKE '[EN][B0]123456%'
ORDER BY Id

--
Hugo Kornelis, SQL Server MVP
Apr 24 '06 #5
Hang on Martin, you didn't ask for that.

Whats your actual requirement?

You can use true regular expressions by using CLR function written in say C#
/ VB.NET.

LEFT( account, 1 ) IN ( .... )

The LIKE is more performant because it can better use an index.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Martin Lukasik" <ma****@milea.pl.i.hate.this.spam> wrote in message
news:26***************************@ZOO.CO.UK...

"Tony Rogerson" <to**********@sqlserverfaq.com> wrote in message
news:e2*******************@news.demon.co.uk...
where ( account like 'EB%
or account like 'NB%' )
and ( account like 'E0%
or account like 'N0%' )
and len( account ) between 6 and 7


Thank you,

Is there any easier way?
What if first characters are A, D, C, 4, X, Z, Y? It's not really nice to
type every permutation.
There must be some regular expression...

Martin

Apr 24 '06 #6
Check out the following link from the code project.

http://www.codeproject.com/managedcpp/xpregex.asp

It provides C++ external functions for SQL Server 2000 that I assume is
usable from 2005 as well. Unlike some onelse who said that LIKE is
faster it is not, this flies!

Andy Blum

Apr 24 '06 #7
(an******@gmail.com) writes:
Check out the following link from the code project.

http://www.codeproject.com/managedcpp/xpregex.asp

It provides C++ external functions for SQL Server 2000 that I assume is
usable from 2005 as well. Unlike some onelse who said that LIKE is
faster it is not, this flies!


Yes, but in SQL 2005 you call functions written in a CLR language,
where you can use the Regexp classes in the .Net Framework. This is a
lot more effecient than calling extended stored procedures.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 24 '06 #8
> Hi Martin,

Try

SELECT * -- Use column list instead!!
FROM table
WHERE account LIKE '[EN][B0]123456%'
ORDER BY Id


That's exactly what I was looking for.
Thank you!

m.
Apr 26 '06 #9
There are a few good blogs about reg ex and ms-sql 2005 with CLR such
as http://blogs.msdn.com/sqlclr/archive.../29/regex.aspx

Also microsoft also provides the code to do it in c# and vb.net in the
sql server 2005 samples download
http://www.microsoft.com/downloads/d...displaylang=en

Hope that is the correct one. look in the find example and they have
all the code the a regex parser.

May 1 '06 #10
http://www.sqlservercentral.com/colu...olkitpart2.asp

"Martin Lukasik" <ma****@milea.pl.i.hate.this.spam> wrote in message
news:68**************************@ZOO.CO.UK...
Hi,

I'm not a big friend of MSSQL, but I have to do one query I've done for
mySQL.
But I don't know how...

I have to select 'user' from 'db' where first letter is E or N, second is
B or 0 and after that there are 6 or 7 digits I know.
How can I do that?

In mySQL it would be something like:

SELECT * FROM `table` WHERE `account` regexp '^[EN][B0]123456$' ORDER BY
`Id`;
Thanks in advance,
Martin

May 18 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eric B. | last post by:
Hi, I'm hoping someone can help me come up with a regular expression that I need to match the following. I'm looking to match all occurances of format <word>.<word> in a string that is not...
2
by: bissatch | last post by:
I am trying to compare two variable but using regular expression: $access = "glasgow" $areaid = "glasgow-westend-byers_rd" using the two variables, I would like the areaid variable to be...
2
by: Mike Andrews | last post by:
Guys, I've got a regular expression that will just not work. I can't get it work properly and I would like to see if someone out there can tell me if I'm doing this wrong, or if there is a...
2
by: IKAS | last post by:
I am having some difficulty in using Regular expression in .NET with C#. How do I write a regular expression so that it will match both the following strings and also get me the relevant named...
4
by: Xavier | last post by:
hello, in a string which i read from a textfile there are some lines, which must be eliminated. The content of the stringvariable is for example : myString=" --comment 1 Update ........
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
1
by: othellomy | last post by:
I am trying to exclude all strings that has 'a' inside (I have simplified the actual problem) select 1 where 'bb b a dfg' like '%%' However, the above does not work. By the way, I can not use...
8
by: Nicodemas | last post by:
Hello all, could not find a regular expression forum, so I thought I would post it to my favorite of the forums. I have a series of applications I've developed which all use a centralized...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.