Solved

When would _ Wildcard actually be useful?

Posted on 2013-01-29
3
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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