I
I
Ilya2020-06-24 13:49:17
SQL Server
Ilya, 2020-06-24 13:49:17

How to combine "in" and "case"?

I can write such a predicate in where

select *
from customer
inner join documents on documents.customer_id = customer_id
where customer.type = case ... end

It doesn't work that way with the "in" construct, what other way can it be done?
It is necessary that, depending on the type of user, different groups of documents are returned
select *
from customer
inner join documents on documents.customer_id = customer_id
where documents.id in case when customer.type = 'A' then (1,2,3) when customer.type = 'B' then (3,5,6) end


I should end up with something like this:

customer1 - customer_typeA - document1
customer1 - customer_typeA - document2
customer1 - customer_typeA - document3

customer2 - customer_typeB - document3
customer2 - customer_typeB - document5
customer2 - customer_typeB - document6

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2020-06-24
@illaaa

in implies a
case list - implies a single value , of
course you can pervert and do something like ... in (case...end)but why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question