我需要过滤的SQL查询结果,根据3个条件:
1.位置
2.医生姓名
3.专业名称SQL语句过滤结果
下面是SQL查询,如果所有的3个条件不是空的:
if (location != "" && doctor!="" && specialty!="")
select Location, ...
from clinicdoctors
where Location = @Location and DoctorName = @DoctorName and SpecialtyName = @SpecialtyName
}
如果只有位置是空的,
if (location == "" && doctor!="" && specialty!="")
select Location, ...
from clinicdoctors
where Location is not null and DoctorName = @DoctorName and SpecialtyName = @SpecialtyName
...
如果我想检查所有的条件,我需要写八个if语句。 在这种情况下我应该怎么做来简化代码?
是SQL Server查询? – anishMarokey 2010-10-11 03:55:50
是的,它是sql服务器查询 – Billy 2010-10-11 03:59:19