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
 select one record

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2013-09-18 : 11:08:52
Hi All.

I have view with Patients name and Appointment table where I save those patients. How to create store procedure if I would like to select one patient record based on Patient_Id value?

Thanks.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-09-18 : 11:15:57
Like this. The red portions if you have multiple rows for a patient and you want to select only one row
create procedure dbo.GetOnePatient
@Patient_ID int
as
set nocount on;
select TOP (1) col1,col2,col3,...
from Appointment
where patient_id = @Patient_ID
Order by somecolumn
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-09-18 : 11:16:12
[code]CREATE PROCEDURE dbo.uspMyFirstProcedure
(
@PatientID INT
)
AS

SET NOCOUNT ON

SELECT *
FROM dbo.vwMyView
WHERE PatientID = @PatientID;
GO[/code]
EXEC dbo.uspMyFirstProcedure 12;



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2013-09-18 : 11:28:53
Thanks for replays.

I forgot to say the Patients view and Appointments table should be join on Patient_Id or unit between. Is it possible?

Thanks.
Go to Top of Page
   

- Advertisement -