我需要過濾的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