我有一个基本的SQL从: " ~' u, }# _8 X, HSELECT top 20 application_id,[name],location_id FROM apps现在,我想完成这一点(用伪代码编写)* }) X+ V9 P4 U, q$ h
if @lid > 0 then WHERE location_id IN (@lid)else WHERE location_id is all values in location_id column根据要求,这是一个示例 : A" f$ _; H2 d& E) j0 z9 ~# ?, ]application_id name location_id---------------------------------------------------------- Joe Blogs 332 Sam Smith Jeremy Carr @locid例如,用户给出的结果‘33,234’ g+ \8 U1 y; S* |如果@lid所以我希望它能输出name和application_id的location_id的所有行。否则,我希望它输出与@lid所有与数字相关的行(代表location_id。; Z3 h" v2 ^$ J1 _. A- r4 n
因此,如果@lid为0: : j" K$ d, k7 \9 Sapplication_id name location_id---------------------------------------------------------- Joe Blogs 332 Sam Smith Jeremy Carr 否则,如果@lid包含“ 33” 5 p( f* f$ e) d' \application_id name location_id---------------------------------------------------------- Joe Blogs 33333 Jeremy Carr 3333 7 M0 g- {% k5 {! e0 ~ 解决方案: # H- A! V) O7 {, Q% w" T
尝试使用 Case ,它满足IIF或者三元运算符的目的。请检查此链接http://msdn.microsoft.com/en-: k% ?1 q3 u9 C% y; a8 q" {1 w
us/library/ms181765.aspx # U5 W$ k' x/ k2 ^# @5 k干杯