SQL SPROC returning some duplicate records?

UPDATE 2 : My bad..I didn't know you could use top like that see updated code for correct syntax.

UPDATE 2 : My bad..I didn't know you could use top like that see updated code for correct syntax - If you need to do a top and distinct you need to it like - select distinct top (@RecordCount) p. ProductID, p. Name, pv.VariantID..so on I do suggest you look at using a group by and rewriting your query to your needs.

You should not use distinct for that many columns.

Thanks Misnomer, that was my attempt at distinct. I don't understand how the group by would help with selecting distinct. – chuck Nov 16 at 16:24 The @RecordCount is the number of records to return, I tried: select top(@RecordCount) DISTINCT p.

ProductID,... but get an "Incorrect syntax near the keyword 'DISTINCT' error – chuck Nov 16 at 16:29 Well, Group by and Distinct can be used interchangeably at times, but more important is understanding what you need. Look at - blog.sqlauthority. Com/2007/03/29/… – Misnomer Nov 16 at 16:35 You cannot do top(@RecordCount) did you look at the syntax as I mentioned in my answer?

– Misnomer Nov 16 at 16:35 That doesn't make sense, it has worked with the top(@RecordCount) for years... it is just a variable being passed in to determine how many records should be returned, since this SPROC is used all over the application we needed it to be flexible. – chuck Nov 16 at 16:39.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions