• Are you looking for something like this?

    CASE WHEN Sum(poitem.qty_ordered) = Sum(poitem.qty_received) AND Sum(poitem.qty_voucher) = Sum(poitem.qty_received)

    THEN 0 ELSE 1 END

    Are you aware on what the NOLOCK hint does? Are your users aware that they can get inconsistent results? Are they fine with that? Do you know that it's not a go-fast option?

    http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx

    http://www.jasonstrate.com/2012/06/the-side-effect-of-nolock/

    http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/11/10/1280.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2