|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help writing SP to do search
I have tables that store data for Patients and Diagnosis information.
Diagnosis Table dgID Primary Key dgName Patient Table ptID Primary Key ptAdmissionDate ptLastName ptFirstName ptAdmittingIntern There can be a number of Diagnoses for each patient so I have a 'link' table that stores which diagnoses is for which patient. PatientDiagnoses Table pdID pdPatientID Foreign key to Patient Table pdDiagnosisID Foreign key to Diagnosis Table I need to search the Link table for a list of diagnoses and return a recordset of the Patient Identity (one record per patient) for patients that match any of the diagnoses. I have written the following stored produre, CREATE PROCEDURE [spPatients] @Diagnosis [int] = Null AS SELECT DISTINCT plID FROM Patients LEFT JOIN PatientDiagnoses ON plID = pdPatient WHERE pdDiagnosis = @Diagnosis GO I need to change this SP to allow for the caller to specify multiple Diagnosis ID's! Anybody have any suggestions? Thanks in advance. Paul |
|
#2
|
||||
|
||||
|
just call it through a loop, sending a different id everytime.
something like this. This will call the stored procedure 9 times, passing it a different Diagnosis id each time. Code:
Let's pretend (i) is the diagnosis id
For i = 1 To 9
rs = Conn.Execute("EXEC dbo.spPatients @Diagnosis = i")
If(rs.eof) Then
Response.write("No records returned")
Else
Response.write the fields here
End If
Next
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Help writing SP to do search |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|