convert tSQL mySQL to MSSQL

  • 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,

    ............

  • 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

  • perfect thanks MickyT

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply