#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    11
    Rep Power
    0

    Convert tSQL from 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,
    ............
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,212
    Rep Power
    4279
    Code:
    SELECT 100.0 *
           ( COUNT(CASE WHEN rating = 5
                        THEN 'ok' ELSE NULL END) -
             COUNT(CASE WHEN rating < 4
                        THEN 'ok' ELSE NULL END) ) /
           COUNT(CASE WHEN rating > 0
                      THEN 'ok' ELSE NULL END) AS recent_nps
         , COUNT(CASE WHEN rating > 0
                      THEN 'ok' ELSE NULL END) AS recent_ratings
         ,
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo