T-SQL - Using AND condition only if a value from a list is present
问题 I want to add an AND condition in my query after the WHERE clause only if I find (a) value(s) from a list of predefined values, otherwise the condition should not be added. The condition I want to add here is "AND Table2.fieldvalue = importantvalue" only when a parameter value is present in a list of (1001, 1002, 1003, 1004, 1005, 1006, 1007) Also the parameter that comes in is a STRING with INT values comma separated but I have a user defined function to split and cast it into INT SELECT