Using CASE in WHERE Statement when parameter has multiple values

后端 未结 3 1983
北海茫月
北海茫月 2021-01-24 00:07

I have a problem which I think relates to having a multiple value parameter.

In my TblActivity there are two fields TblActivity.ActivityServActId

3条回答
  •  心在旅途
    2021-01-24 01:03

    In SQL, the IN clause does not support parameters the way you are using them. The general syntax is

    IN (1, 2, 3, 4)
    

    you have

    IN (@Param)
    

    where something like @Param = '1, 2, 3, 4'

    Internally, SQL will turn this into

    IN ('1, 2, 3, 4')
    

    Note the quotes... you are now matching against a string!

    There are a number of ways to address this. Search SO for "sql in clause parameter", pick one that works for you, and upvote it.


    (Added)

    Parameterize an SQL IN clause seems pretty definitive on the subject. While long ago I upvoted the third reply (the one with table-value parameters), any of the high-vote answers could do the trick. The ideal answer depends on the overall problem you are working with. (I am not familiar with SSRS, and can't give more specific advice.)

提交回复
热议问题