sql server - T-SQL - how to compare a SELECT resultset and IN list -
this question has answer here:
i have query , in clause want add , condition if resultset of 1 select statement in list of predefined values, otherwise condition should not added
select field1, field2, field3 .... table1 join table2 on somekeymappings condition1 , condition2 , if (select ids table2) in (1001, 1002, 1003, 1004, 1005, 1006) condition3 group blah, blah, blah having blah, blah
select field1, field2, field3 .... table1 join table2 on somekeymappings condition1 , condition2 , (table2.id in (1001, 1002, 1003, 1004, 1005,1006) , condition3 or table2.id not in (1001, 1002, 1003, 1004, 1005,1006)) group blah, blah, blah having blah, blah
Comments
Post a Comment