• 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