Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1979
  • Last Modified:

How do I use IN and LIKE together

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
Mr_Shaw
Asked:
Mr_Shaw
  • 2
1 Solution
 
adatheladCommented:
Hi,

No, it's not possible - you'll need to have multiple clauses:
WHERE (product LIKE 'shoe%' OR product LIKE 'tops%'......)
0
 
Mr_ShawAuthor Commented:
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
 
Kevin CrossChief Technology OfficerCommented:
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
 
Mr_ShawAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

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