473,396 Members | 1,764 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,396 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 73763
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.