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.
| Author |
Topic |
|
robson
Starting Member
22 Posts |
Posted - 2008-07-31 : 11:36:04
|
| I have the following Stored Procedure which brings up duplicate redcords, how would I change it select Unique records. Thank you.CREATE PROCEDURE <SP_NAME> @categoryID int, @row_number int, @sub_categoryID intASSELECT TOP 10 * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY patient.patientID ORDER BY patientLastName, patientFirstName) AS RowNumber, patient.patientID, patientFirstName, patientLastName, patientDOB, patientGender, allocated FROM patient INNER JOIN patient_record ON patient.patientID = patient_record.patientIDINNER JOIN sub_category ON sub_category.sub_categoryID = patient.sub_categoryIDINNER JOIN category ON category.categoryID = sub_category.categoryIDWHERE (allocated = case when @categoryID<>12 then @sub_categoryID else allocated end) AND (risk = 6) AND (completed_date = '' OR completed_date IS NULL)GROUP BY patient.patientID, patientFirstName, patientLastName, patientDOB, patientGender, allocated) _myResultsWHERE RowNumber > @row_number |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-31 : 12:56:53
|
| Without seeing your data and your expected o/p its very difficult to understand wht you mean by duplicates. Can you illustrate with some sample data what you are expecting for an output? |
 |
|
|
|
|
|
|
|