Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

SQL Like statement with multiple values

Malekish (TechnicalUser) (OP)
22 Dec 08 12:18
Hi all, I tried searching for a previous example however using the work 'like' gives many, many results :)

I have a report I've inherited and I'm stuck on a problem.  Querying MS SQL Server and I'm trying to get a list of Object_IDs.

Example of table 1

Date_field, object_id, data_field1, data_field2...
20081201, CS4_1_194, 524, 23.....

Example of table 2

Object_ID, Object_Name, Object_Type...
CS4_1_194, 396628@dsm_siemens_hicom, 4

Obviously I can use Object_ID from both tables however the data handed to me includes an extensive list of items, all given with Object_Name instead of Object_ID.  What I want to do is find the Object_IDs to build another query.

I know I can
select Object_ID from Table2 where Object_Name like '396628@%'

What is the format if I want to include several of those names?  The following error gives me syntax errors.

Select Object_ID from Table2 where Object_Name
like ('396628@%', '396629@%', '396630@%')


Thanks in advance for any help!
 
PHV (MIS)
22 Dec 08 12:45
Select Object_ID from Table2
where Object_Name like '396628@%'
OR Object_Name like '396629@%'
OR Object_Name like '396630@%'
 

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Malekish (TechnicalUser) (OP)
22 Dec 08 16:46
Ok, so I do have to do it as ORs.    I found one example on the net after posting this question and was hoping there'd be a better solution.

Thanks much PH!
PHV (MIS)
23 Dec 08 3:08
An ANSI SQL another way:
SELECT Object_ID FROM Table2
WHERE SUBSTRING(Object_Name FROM 1 FOR 7) IN ('396628@','396629@','396630@')
 

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close