Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

convert tSQL mySQL to MSSQL Expand / Collapse
Author
Message
Posted Sunday, April 21, 2013 6:18 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:52 PM
Points: 32, Visits: 129
Hi Guys need some help with converting this part of a query from MySQL, I need to run this on MSSQL.

Select (SUM(if(rating = 5, 1, 0))-SUM(if(RATING < 4, 1, 0)))/SUM(if(RATING > 0, 1, 0))*100 as RECENT_NPS,
SUM(if(RATING > 0, 1, 0)) as RECENT_RATINGS,
............
Post #1444835
Posted Sunday, April 21, 2013 8:50 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 1:14 PM
Points: 951, Visits: 2,882
Hi

Try replacing your IF functions with a CASE statements, eg

if(rating = 5, 1, 0)

becomes

CASE WHEN rating = 5 THEN 1 ELSE 0 END

In SQL 2012 there is also the IIF function that could be used


Post #1444840
Posted Sunday, April 21, 2013 10:44 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:52 PM
Points: 32, Visits: 129
perfect thanks MickyT
Post #1444849
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse