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: Thursday, July 31, 2014 3:02 AM
Points: 32, Visits: 132
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
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, December 10, 2014 12:17 PM
Points: 1,095, Visits: 3,182
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: Thursday, July 31, 2014 3:02 AM
Points: 32, Visits: 132
perfect thanks MickyT
Post #1444849
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse