?
Solved

How do i use an SQL select query to return a result using a small part of the data

Posted on 2014-09-03
5
Medium Priority
?
270 Views
Last Modified: 2014-09-03
I need an SQL select query which gives me results when i enter a few characters from a value

For e.g.

SELECT    * from Table
WHERE      column like Like 'ABC%'
order by XYZ;

Here the value 'ABC' is just a small part of the value and i want to this query to return the results which contain the value 'ABC' in it. For example -- ABC can be present in the server hostname

Hope this helps.
0
Comment
Question by:Kailash Kapal
[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
  • 3
  • 2
5 Comments
 
LVL 37

Assisted Solution

by:Neil Russell
Neil Russell earned 2000 total points
ID: 40302266
You have the answer in your question. Did i miss something or do you want ABC  ANYWHERE in the column?
If so then just use  LIKE '%ABC%'
0
 

Author Comment

by:Kailash Kapal
ID: 40302279
Thanks Neilsr ..that worked to some extent ...Now i have one more query if you can assist ....

If in case, i want multiple hostnames to be present in the query, can i use  -- Like '%ABC%, %DEF%' --  something like that...
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 2000 total points
ID: 40302284
SELECT    * from Table
WHERE      column like Like '%ABC%'
OR
column like Like '%DEF%'
OR
column like Like '%LMN%'
order by XYZ;
0
 

Author Comment

by:Kailash Kapal
ID: 40302308
Thanks again ... can't we have multiple values OR input the values via text file

For e.g.  for having multiple values ..i meant to have -- column like '%ABC%','%DEF%'  -- Let me know if it is possible

For inputting the values via text file/ csv file  as we do in powershell or any script
0
 
LVL 37

Assisted Solution

by:Neil Russell
Neil Russell earned 2000 total points
ID: 40302324
Of course, you could even do the SQL query from Powershell.

Here is a very good use of using a temporary table to do your Multiple Likes.....

http://stackoverflow.com/questions/1387612/how-can-i-introduce-multiple-conditions-in-like-operator

About halfway down see the answer headed "This is a good use of a temporary table."
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

771 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