Is there a way to get a Stored Procedure to return only unique records from a table? I am using a Stored PRocedure to query a table and it returns all the records in the table and there are many duplicates in the information. I am using SQL Server 2K.
"distinct" will provide you the unique records for the fields you request. If you use Select Distinct * from table, and you have a primary key in your table, you will always get all records returned.
However, if you use Select Distinct Field1, Field2, Field3... from table (where Field1, Field2, Field3 are the fields of information you want in your answer) then you will get a list of unique records.
I agree. DISTINCTis the "correct" way to specify that the query-result should contain no duplicates. And, as a rule of thumb, you should always be sure that your query specifies what you want, not how you think the DBMS should produce it! SQL is not a "procedural" language.