这是我的存储过程,我与水晶报告连接,我想返回开始日期和结束日期,这是我从参数,如果日期为空,然后没有显示报告,但如果日期有一些值,那么价值印刷品。
CREATE PROCEDURE [dbo].PatientClaimInfo
@StartDate Date = NULL,
@EndDate Date = NULL
AS
BEGIN
select p.VLNAME + ' ' + p.VFNAME AS Patients_Name, p.IPATID AS Patient_ID, p.DDOB AS dob,
d.NCOPAY, d.NVTOTPLAN, d.NVWOPLAN, d.NVWOPAT, d.NVADJPLAN, d.NVADJPAT, d.NVPAIDPLAN,
d.NVPAIDPAT, d.NVBALPLAN, d.NVBALPAT, d.NAPPTBAL, d.VPAYSTAT AS Status
From pmvixtr d
INNER JOIN pmptxft p ON p.IPATID = d.IPATID
Where @StartDate <= d.DSDATE AND @EndDate >= d.DSDATE
END
答案 0 :(得分:1)
尝试
CREATE PROCEDURE [dbo].PatientClaimInfo
@StartDate Date = NULL,
@EndDate Date = NULL
AS
BEGIN
IF (@StartDate Date IS NOT NULL AND @EndDate Date IS NOT NULL)
THEN
select p.VLNAME + ' ' + p.VFNAME AS Patients_Name, p.IPATID AS Patient_ID, p.DDOB AS dob,
d.NCOPAY, d.NVTOTPLAN, d.NVWOPLAN, d.NVWOPAT, d.NVADJPLAN, d.NVADJPAT, d.NVPAIDPLAN,
d.NVPAIDPAT, d.NVBALPLAN, d.NVBALPAT, d.NAPPTBAL, d.VPAYSTAT AS Status
From pmvixtr d
INNER JOIN pmptxft p ON p.IPATID = d.IPATID
Where @StartDate <= d.DSDATE AND @EndDate >= d.DSDATE
END
END
答案 1 :(得分:1)
在您的select语句中,您可以包含@StartDate,@ EndDate
e.g。
select @StartDate, @EndDate, .... <rest of your select statement>...
我还建议在你的where子句中使用where d.DSDATE BETWEEN(@StartDate,@ EndDate)
如果你不想在@StartDate和@EndDate为NULL时选择任何东西,那么在WHERE Clause中使用它可能非常昂贵...我建议有一个if条件
IF @StartDate IS NOT NULL AND @EndDate IS NOT NULL
select.....
END IF