sql查询语句(全查或查指定数据)

ALTER PROCEDURE [dbo].[qryDoctorHours]
(
@DoctorID int,
@startFrom smalldatetime,
@endTo smalldatetime
) AS

BEGIN
declare @surefromdate smalldatetime
if @startFrom is null
set @surefromdate=cast(convert(varchar(10),getdate(),120) as datetime)
else
set @surefromdate=@startFrom
select d.*, u.realName as doctorName
from doctorHours d
left join doctor doc on d.doctorId = doc.id
left join users u on u.id = doc.userId
where (@DoctorID=0 or d.doctorId = @DoctorID)
and ( d.clinicDate between @surefromdate and @endTo)
order by d.clinicDate, d.ampm asc;

END

 

如果@DoctorID(dropdown中选中的值)的value=0,表示查询所有的医生信息,否则查询指定的医生信息

posted @ 2013-01-14 16:52  solo~  阅读(1248)  评论(0编辑  收藏  举报