[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I use IN and LIKE together

Posted on 2008-10-13
4
Medium Priority
?
1,972 Views
Last Modified: 2012-08-13
I have a query where I need to use IN and LIKE together.

For example;

FOR product IN (like shoe%, like tops%, like bottoms%)

is this possible?
0
Comment
Question by:Mr_Shaw
[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
4 Comments
 
LVL 23

Expert Comment

by:adathelad
ID: 22701366
Hi,

No, it's not possible - you'll need to have multiple clauses:
WHERE (product LIKE 'shoe%' OR product LIKE 'tops%'......)
0
 

Author Comment

by:Mr_Shaw
ID: 22701409
Thanks,

I am now a bit stuck slotting this LIKE clause into my nested query which I am using as part of a SQL Pivot.

I have created a Pivot which select items C100 and C200. How do I use Like here for example can I do

sleect AttendanceDate Like 'C100%'

My original code is:


SELECT     AttendanceDate, [C100] AS C1, [C200] AS C2
FROM         (SELECT     AttendanceDate, Derived_Provider
                       FROM          OPA_General
                       WHERE      (AttendanceDate BETWEEN CONVERT(DATETIME, '03 /01/ 2007 00:00:00', 103) AND CONVERT(DATETIME, '05/03/2007 00:00:00', 103)))
                      p PIVOT (COUNT(Deriverd_Provider) FOR Derived_Provider IN (C100, C200)) AS pvt
ORDER BY AttendanceDate
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22701672
For PIVOT, you need harcoded column names, so you would have to explicitly type out all the value C100x values or use dynamic SQL statement to build your query.  If the list of values is short and consistent, I would suggest always going with the handcoded method.
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31505562
I am going to hardcode the Pivot.
I ran a check and there are only two variations. Not really worth setting up an dynamic SQL.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

649 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