DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MS SQL (http://www.daniweb.com/forums/forum127.html)
-   -   Sql Sort Query.... (http://www.daniweb.com/forums/thread122428.html)

tytyguy May 4th, 2008 6:25 pm
Sql Sort Query....
 
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....

ELSE IF @sortEntityName = 5 BEGIN --Sort By Rating

        INSERT #RowNumber (rating)
        SELECT RT.Productid
        FROM Rating RT
        GROUP BY RT.ProductID
        ORDER BY MIN(RT.Rating)

        INSERT #displayorder select rating, displayorder from #RowNumber
END

Sulley's Boo May 5th, 2008 6:18 am
Re: Sql Sort Query....
 
I tried the link ..
Sorting feature is working fine ..

:-/

campkev May 9th, 2008 2:58 pm
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)

campkev May 9th, 2008 3:03 pm
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)


All times are GMT -4. The time now is 2:24 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC