User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 330,226 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,022 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 233 | Replies: 3
Reply
Join Date: May 2008
Posts: 1
Reputation: tytyguy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tytyguy tytyguy is offline Offline
Newbie Poster

Sql Sort Query....

  #1  
8 Days Ago
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
Last edited by tytyguy : 8 Days Ago at 6:26 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: UAE
Posts: 396
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Whiz

Re: Sql Sort Query....

  #2  
8 Days Ago
I tried the link ..
Sorting feature is working fine ..

Last edited by Sulley's Boo : 8 Days Ago at 6:18 am.
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 480
Reputation: campkev is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 16
campkev campkev is offline Offline
Posting Pro in Training

Re: Sql Sort Query....

  #3  
4 Days Ago
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)
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 480
Reputation: campkev is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 16
campkev campkev is offline Offline
Posting Pro in Training

Re: Sql Sort Query....

  #4  
4 Days Ago
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)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 4:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC