943,515 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 18156
  • MS SQL RSS
May 4th, 2008
0

Sql Sort Query....

Expand Post »
Ok, I have a e-commerce store that uses stored procedures to sort products. I have figured out how to sort my name and price but am having trouble sorting by rating bc the rating table doesnt have all the productids (only ones that have a rating) and also the rating table is in a different table than the products table so when I use the code below it only shows products that have a rating. Heres an example http://www.tunerplaza.com/c-304-carburetion.aspx?


Heres the sql code For the rating....

MS SQL Syntax (Toggle Plain Text)
  1. ELSE IF @sortEntityName = 5 BEGIN --Sort By Rating
  2.  
  3. INSERT #RowNumber (rating)
  4. SELECT RT.Productid
  5. FROM Rating RT
  6. GROUP BY RT.ProductID
  7. ORDER BY MIN(RT.Rating)
  8.  
  9. INSERT #displayorder select rating, displayorder from #RowNumber
  10. END
Last edited by tytyguy; May 4th, 2008 at 7:26 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tytyguy is offline Offline
2 posts
since May 2008
May 5th, 2008
0

Re: Sql Sort Query....

I tried the link ..
Sorting feature is working fine ..

Last edited by Sulley's Boo; May 5th, 2008 at 7:18 am.
Reputation Points: 529
Solved Threads: 10
Posting Pro in Training
Sulley's Boo is offline Offline
450 posts
since Dec 2004
May 9th, 2008
0

Re: Sql Sort Query....

I think you want something like this

Select distinct pt.ProductID
from Products pt
left join Rating RT
on pt.productid = rt.productid
order by IsNull(Min(rt.Rating),0)
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
May 9th, 2008
0

Re: Sql Sort Query....

ignore that last one and try this instead


Select pt.ProductID
from Products pt
left join Rating RT
on pt.productid = rt.productid
group by pt.productid
order by IsNull(Min(rt.Rating),0)
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC