Solved

When would _ Wildcard actually be useful?

Posted on 2013-01-29
3
202 Views
Last Modified: 2013-01-29
I am doing some tutorials and have just learnt about the _ wildcard so for example if in my table i had the first name Dario and wanted to find a name that started with any character followed by 'ario' i would use

SELECT * FROM Person WHERE FirstName LIKE '_ario'

But when would this actually be useful i am struggling to find a reason why you would want to query your database to find something that i suppose logic would help you figure out anyway?

Apologies if in the SQL world this is a stupid question still fairly new to this all!

Thanks, SuperJinx
0
Comment
Question by:SuperJinx
  • 2
3 Comments
 
LVL 4

Expert Comment

by:MimicTech
ID: 38832637
It is just a wildcard charecter that resembles a single char. I have only used it a few times, but it is nice to have.

Let's say you are storing MAC addresses in a table (ie. AA:BB:CC:11:22:33) and you want to pull all of the MAC address that have an OUI (the first 3 octets) ending in CC. For this you would have to select where MAC_ADDR like '__:__:CC:%' .

Geeky example, but you can see where combining the wildcards can give you a bit more flexability.
0
 

Author Comment

by:SuperJinx
ID: 38832652
Thanks for your answer although I have to say the example is a bit too complicated for me at the moment i can't really relate to it although i've read it 5-6 times.

None the less thank you for your answer Mimic.
0
 
LVL 4

Accepted Solution

by:
MimicTech earned 75 total points
ID: 38832886
here is a more busn related example:

let's say you were storing all employee phone numbers: and your corp's phone system was setup that all Accounting telephone were in the 4000's (ie. x4011) and all IT numbers were in the 6000's (ie. x6012). Let's also extend this to say that the office in California had telephone prefixes like 919-430-xxxx and the office in New York had prefixes like 212-679-xxxx.

if you wanted all Accounting telephone numbers in the database you could query

.... where telephone like '___-___-4___'
this would also work ... where telephone like '___-___-4%'

you could also query for all New York IT numbers like this

... where telephone like '212-679-6%'
this would also work ... where telephone like '212-679-6___'
hope this makes it a little clearer.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question