Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Debug Simple Stored Procedure

Author  Topic 

Dallr
Yak Posting Veteran

87 Posts

Posted - 2010-04-15 : 20:34:09
Hello everyone. Can anybody tell me what this Stored Procedure is not returning any results?


ALTER PROCEDURE dbo.BookingData
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
@VisitID varchar,
@PatientID varchar
AS
/* SET NOCOUNT ON */

RETURN
DEclare @isEmp as varchar
set @isEmp = ISNULL(@VisitID,0)
IF @isEmp = 0
begin
SELECT Visits.VisitID, Visits.PatientID, Visits.DateBooked, Visits.TimeBooked, Visits.ReasonForVisit
, Visits.DoctorID, Visits.DoctorsComments, Visits.FollowUpDate, Visits.Cost, Visits.VisitTypeID
, VisitTypes.VisitType, Doctors.FirstName + ' ' + Doctors.LastName AS DoctorsName
FROM VisitTypes INNER JOIN Visits ON VisitTypes.VisitTypeID = Visits.VisitTypeID INNER JOIN
Doctors ON Visits.DoctorID = Doctors.DoctorID WHERE Visits.PatientID = @PatientID ORDER BY VisitID DESC;
end
ELSE
SELECT Visits.VisitID, Visits.PatientID, Visits.DateBooked, Visits.TimeBooked, Visits.ReasonForVisit
, Visits.DoctorID, Visits.DoctorsComments, Visits.FollowUpDate, Visits.Cost, Visits.VisitTypeID
, VisitTypes.VisitType, Doctors.FirstName + ' ' + Doctors.LastName AS DoctorsName
FROM VisitTypes INNER JOIN Visits ON VisitTypes.VisitTypeID = Visits.VisitTypeID INNER JOIN
Doctors ON Visits.DoctorID = Doctors.DoctorID WHERE Visits.PatientID = @PatientID AND Visits.VisitID =@VisitID ORDER BY VisitID DESC;




Dallr

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-15 : 20:37:03
It's because you have RETURN right after the AS. RETURN means to exit the stored procedure! Move the RETURN to the bottom of the code.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Dallr
Yak Posting Veteran

87 Posts

Posted - 2010-04-15 : 21:23:48
Thanks for the feedback Tara Kizer. Now I have another problem. I am passing two values from ASP.net to this SP but when I test it in GUI and pass only one of the values manuall I get the following message.

Procedure or function 'BookingData' expects parameter '@VisitID', which was not supplied.

It seems like it thinks I must pass the @VisitID but this paramter is optional. How can i get around this.
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2010-04-15 : 22:26:07
If its optional you will need to specify this in the procedure (@VisitId varchar(10) = null), and in the application pass System.DbNull.Value
Go to Top of Page

chriztoph
Posting Yak Master

184 Posts

Posted - 2010-04-15 : 22:27:55
Pass a null value in your front-end for the @VisitID if it is not required.
Go to Top of Page

Dallr
Yak Posting Veteran

87 Posts

Posted - 2010-04-16 : 04:36:00
Thanks All I got through!

Dallr
Go to Top of Page
   

- Advertisement -