sql server - Allow multiselect on a CSV column in SSRS -


i trying make parameter multiselect on csv column in report, not sure how or if it's possible. example dataset returned:

|  id  |  name  |      types      | |  1   |  test  |  type a, type b | 

the current dataset using in where clause parameter:

where types '%' + @types + '%' 

this works fine single select, of course doesn't work multiselect. how can make parameter allow multiple values , still search csv column? wish where types in '%' + @types + '%' work, end where types in ('%type a%, %type b%'). or there better way can display column appears csv if sql not doing it? still want display values , see if selected type in list, if parameter set type b should still show type a, type b id = 1. know csvs disliked in sql, seems frequent thing that's asked make csv columns , allow multiselect on it.

there 2 posibilities (1) filter have single value 'type a' (2) filter have multiple values 'type a, type b' here giving solution both 1 , 2. here have used #table make understand easy

dummy data be:

if object_id('tempdb.dbo.#temp') not null begin     drop table #temp; end  if object_id('tempdb.dbo.#temp') null begin     create table #temp     (          id         int identity(1,1) primary key         ,name       varchar(100)         ,types      varchar(2000)     ) end  insert #temp(name,types) values ('test','type a, type b'), ('test1','type a, type c'), ('test2','type b'), ('test3','type c, type a'), ('test4','type c');  declare  @typefilter        varchar(2000) 

posibility 1:

select   @typefilter = 'type c'  select  *    #temp t (nolock)   (',' + t.types + ',') ('%,' + @typefilter + ',%') 

posibility 2:

select   @typefilter = 'type c, type b'  select  distinct         t.*    #temp t (nolock)         join dbo.udf_getsplitvalues(@typefilter,',') p on (',' + t.types + ',') ('%,' + p.stitems + ',%') 

here posibility 2, have used table-value function returns csv values table , applied join primary table.

hope helpful.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -