0

I have a dataset that has two fields Main_Activity and Requesting_Activity

Sample dataset"

Main_activity    Reuesting_Activity
-------------    ------------------
Act1             Act1,Act1a,Act2,Act3
Act2             Act1a,Act3,Act5
Act3             Act1,Act3,Act4
Act4             Act2,Act4,Act5

When I use the SQL query and pass Act1 as parameter (@mainActivity) for the dataset

SELECT DISTINCT
    Main_Activity,
    Requesting_Activity
FROM Activity_table
WHERE Requesting_Activity LIKE ''+ (@mainActivity) +'' OR Requesting_Activity LIKE ''+ (@mainActivity) +',%' OR Requesting_Activity LIKE '%,'+ (@mainActivity) +',%' OR Requesting_Activity LIKE '%,'+ (@mainActivity) +''

I get the expected output

Act1
Act3

The problem is when I make the parameter as multi-select, I am getting error. How do I resolve it? How to use "LIKE and "IN" operator in same query?

11
  • 1
    have a look here: stackoverflow.com/questions/1865353/… its already a duplicate Commented Mar 6, 2015 at 7:27
  • I already had a look at that post, but there the values to be matched are static. In my question it is dynamic. Commented Mar 6, 2015 at 7:30
  • 1
    @damseldeebi your problem is not in SSRS, but in your table design. Multivalue fields are wrong! You are trying to solve a problem in SSRS, when you just need to redesign your table(s). Commented Mar 6, 2015 at 7:40
  • 1
    @damseldeebi I'm sorry, but you are doing it completely wrong. Why do you even care about number of rows, when you are spending A LOT of processing power on LIKEs on multi value fields?? Are you short of hard drive space? Few thousand more records? That's nothing for almost any DMBS, even less on engines like SQL Server that can handle datawarehouses with tables with 30+millions records. Commented Mar 6, 2015 at 9:04
  • 1
    @damseldeebi you are facing the X-Y problem. You are trying to solve "How to retrieve the rows I want" when the only thing your should care about is "How to correctly design a relational database". Multivalues field in a relational database are wrong. Always, no exception. Commented Mar 6, 2015 at 9:08

1 Answer 1

1

your where clause is full of redundancies

WHERE Requesting_Activity LIKE '%'+ (@mainActivity) +'%'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.