sql - Return date which I get as parameter in Stored Procedure -


this stored procedure connecting crystal report , want return start date , end date getting parameters if date null nothing shows on reports if date has value value prints.

create procedure [dbo].patientclaiminfo  @startdate date = null, @enddate date = null  begin select p.vlname + ' ' + p.vfname patients_name, p.ipatid patient_id, p.ddob 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 status   pmvixtr d  inner join  pmptxft p on p.ipatid = d.ipatid   @startdate <= d.dsdate , @enddate >= d.dsdate  end 

in select statement can include @startdate, @enddate

e.g.

select @startdate, @enddate, .... <rest of select statement>... 

i suggest in clause use d.dsdate between(@startdate, @enddate)

if don't want select if @startdate , @enddate null, having in clause can expensive... suggest have if condition

if @startdate not null , @enddate not null select.....  end if 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -