fix for CASE expression in query with offset in ms sql