Finding a NULL value in the record set

  • CREATE TABLE kiQCTest (

    OrderNum varchar(10),

    OrderLine int,

    QCPass bit)

    INSERT INTO kiQCTest ([OrderNum] ,[OrderLine]) VALUES ('OD15-00010', 1)

    INSERT INTO kiQCTest ([OrderNum] ,[OrderLine]) VALUES ('OD15-00010', 2)

    INSERT INTO kiQCTest ([OrderNum] ,[OrderLine]) VALUES ('OD15-00010', 3)

    INSERT INTO kiQCTest ([OrderNum] ,[OrderLine],[QCPass]) VALUES ('OD15-00010', 4, 1)

    INSERT INTO kiQCTest ([OrderNum] ,[OrderLine],[QCPass]) VALUES ('OD15-00010', 5, 1)

    INSERT INTO kiQCTest ([OrderNum] ,[OrderLine],[QCPass]) VALUES ('OD15-00010', 6, 0)

    I want to write a select statement which will return one value. Thes resulting value is 'Quality Complete' if there are no NULL value in the QC Pass field in the dataset.

    Or it should return me 'QC Incomplete'.

  • Something like this?

    select kqt.OrderNum

    ,QCStatus = (case when count(kqt.OrderNum) - count(kqt.QCPass) > 0 then 'QC Incomplete'

    else 'QC Complete'

    end)

    from dbo.kiQCTest kqt

    group by kqt.OrderNum


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply