SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SP for voting help needed
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 04/25/2013 :  18:01:04  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
Hi All,

I got this

SELECT (T_Review_Votes.positive-T_Review_Votes.negative) AS score,T_Review.ReviewID, T_Review.CustomerName, T_Review.Rating, T_Review.Comments, T_Review_Votes.positive, T_Review_Votes.negative
FROM T_Review LEFT OUTER JOIN
T_Review_Votes ON T_Review.ReviewID = T_Review_Votes.reviewid
WHERE (T_Review.ProductID = @ProductID) AND (T_Review.lang = @lang) AND (T_Review.active = 1)
ORDER BY score desc

Which displays the customer reviews, and orders the ones with the positive votes on top.
But now i got a problem, because many reviews do not have votes
But i want the with negative votes to the bottom and the Nulls in the middle

Thanks a lot

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/25/2013 :  18:35:29  Show Profile  Reply with Quote
Hard to say since you didn't show us any data or expected output... maybe COALESCE the null values to zero?
Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 04/25/2013 :  21:24:50  Show Profile  Reply with Quote
quote:
Originally posted by Lamprey

Hard to say since you didn't show us any data or expected output... maybe COALESCE the null values to zero?



The following change should work:



SELECT (COALESCE(T_Review_Votes.positive, 0)- COALESCE(T_Review_Votes.negative,0)) AS score,T_Review.ReviewID, T_Review.CustomerName, T_Review.Rating, T_Review.Comments, T_Review_Votes.positive, T_Review_Votes.negative
FROM T_Review LEFT OUTER JOIN
T_Review_Votes ON T_Review.ReviewID = T_Review_Votes.reviewid
WHERE (T_Review.ProductID = @ProductID) AND (T_Review.lang = @lang) AND (T_Review.active = 1)
ORDER BY score desc

Go to Top of Page

mike13
Posting Yak Master

Netherlands
214 Posts

Posted - 04/26/2013 :  04:40:08  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
Thanks a lot MuMu88 that did the trick
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000