• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

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

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
Kailash Kapal
Asked:
Kailash Kapal
  • 3
  • 2
3 Solutions
 
Neil RussellTechnical Development LeadCommented:
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
 
Kailash KapalIdM Project Lead (India Ops)Author Commented:
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
 
Neil RussellTechnical Development LeadCommented:
SELECT    * from Table
WHERE      column like Like '%ABC%'
OR
column like Like '%DEF%'
OR
column like Like '%LMN%'
order by XYZ;
0
 
Kailash KapalIdM Project Lead (India Ops)Author Commented:
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
 
Neil RussellTechnical Development LeadCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now