我想要实现的是:
- 当选择值为空时->;所有的约会都出现了
- 当设置选择值时->只有特定医生的预约
查询:
SELECT a.ward_id,
a.doc_id,
a.id_patient,
a.dt_Sched,
a.dt_Sched_end,
a.sched_time,
to_char(a.sched_duration,'0.0') sched_duration,
a.sched_id,
a.hosp_ward,
c.surname||' '||c.name || ' - time :' ||a.sched_time Display,
d.description
FROM t_schedule a,
T_doctors b,
t_patient c,
t_Ward d
WHERE a.doc_id = b.doc_id
and c.id_patient = a.id_patient
/* and b.doc_id = :PselectList*/ > Select list for which doctor
and d.ward_id= a.ward_id
不带:'和b.doc_id=:PselectList'
- 显示日历中的所有约会
带有:'和b.doc_id=:PselectList'
- 如果选择值设置为空-->日历中没有约会
- 如果选择值设置为非空,则医生-->按选定值显示日历中筛选的约会
使用nvl:解决
WHERE a.doc_id = b.doc_id
and c.id_patient = a.id_patient
and b.doc_id = nvl(:PselectList, b.doc_id)
and d.ward_id= a.ward_id
如果我理解正确,那么它应该是
from t_schedule a join t_doctors b on a.doc_id = b.doc_id
join t_patient c on c.id_patient = a.id_patient
join t_ward d on d.ward_id = a.ward_id
where (b.doc_id = :P3008_SELECTLIST or :P3008_SELECTLIST is null)
(顺便说一句,你真的使用MS SQL Server作为数据库吗?它不是Oracle吗?如果是,修复标签。(