By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,044 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,044 IT Pros & Developers. It's quick & easy.

Wildcards On Columns?

P: n/a
My use of wildcards thus far has been limited to matching a given
string anywhere in a column as follows:

SELECT * FROM Table WHERE Column LIKE '%string%'

However, I'm wondering if there's a way to do this in reverse. That
is, is there a way to match the column anywhere in the string?
Pseudo-coding it as:

SELECT * FROM Table WHERE 'string' LIKE %Column%

What I'm trying to match is network addresses. Most of the stored
addresses in this table are exact (i.e. ip-1-2-3-4.location.isp.com)
but sometimes they encompass an entire group (i.e. location.isp.com).
When an exact address is given in the code I'm writing, it needs to
match any rows that contain its exact self or contain a shortened
version of which it is part.

Any ideas?
-cyber0ne
http://www.cyber0ne.com

Nov 29 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
cyber0ne wrote:
My use of wildcards thus far has been limited to matching a given
string anywhere in a column as follows:

SELECT * FROM Table WHERE Column LIKE '%string%'

However, I'm wondering if there's a way to do this in reverse. That
is, is there a way to match the column anywhere in the string?
Pseudo-coding it as:

SELECT * FROM Table WHERE 'string' LIKE %Column%

What I'm trying to match is network addresses. Most of the stored
addresses in this table are exact (i.e. ip-1-2-3-4.location.isp.com)
but sometimes they encompass an entire group (i.e. location.isp.com).
When an exact address is given in the code I'm writing, it needs to
match any rows that contain its exact self or contain a shortened
version of which it is part.

Any ideas?
-cyber0ne
http://www.cyber0ne.com

SELECT *
FROM Table
WHERE 'string' LIKE '%'+Column+'%' ;

--
David Portas
SQL Server MVP
--

Nov 29 '05 #2

P: n/a
> SELECT *
FROM Table
WHERE 'string' LIKE '%'+Column+'%' ;


That's returning all rows, regardless of the string.

Nov 29 '05 #3

P: n/a
cyber0ne (cy*******@gmail.com) writes:
SELECT *
FROM Table
WHERE 'string' LIKE '%'+Column+'%' ;


That's returning all rows, regardless of the string.


Then it's time for the standard advice for questions of this type. And that
is that you should always include:

o CREATE TABLE statement for your table (preferrably simplified)
o INSERT statements with sample data.
o The desired result given the sample.

With just a narrative that may not be complete, there is a risk for
misunderstandings. Also, with the information above, it's simple to
post a tested solution.

--
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
Nov 30 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.