• This is an indication that your data is poorly structured.

    you are using a text field to represent a binary value (Pass/fail)

    I would suggest the introduction of a lookup table

    declare @TestStatus as table

    (

    TestStatusDescription nvarchar(50),

    TestResult int

    )

    insert into @testStatus (TestStatusDescription,TestResult) values ('OK',1)

    insert into @testStatus (TestStatusDescription,TestResult) values ('Pass',1)

    insert into @testStatus (TestStatusDescription,TestResult) values ('Fail',0)

    insert into @testStatus (TestStatusDescription,TestResult) values ('Not OK',0)

    ...

    one record for every description in your table: you can find these by doing a SELECT DISTINCT on the relevant field.

    Then join to this @TestStatus table to return 1 or 0 and use the MIN() functionality to determine whether any test has failed.