• great job on giving us the setup DDL and Data.

    Your data has all the same datetimes, so it'll probably look better when you compare the example with real data.

    this seems to work for me, is this what you are after?

    SELECT

    ID,

    PO,

    CASE WHEN ISNULL(timestamp1,'1900-01-01') >= ISNULL(timestamp2,'1900-01-01')

    AND ISNULL(timestamp1,'1900-01-01') >= ISNULL(timestamp3,'1900-01-01')

    AND ISNULL(timestamp1,'1900-01-01') >= ISNULL(timestamp4,'1900-01-01')

    THEN ISNULL(timestamp1,'1900-01-01')

    WHEN ISNULL(timestamp2,'1900-01-01') >= ISNULL(timestamp1,'1900-01-01')

    AND ISNULL(timestamp2,'1900-01-01') >= ISNULL(timestamp3,'1900-01-01')

    AND ISNULL(timestamp2,'1900-01-01') >= ISNULL(timestamp4,'1900-01-01')

    THEN ISNULL(timestamp2,'1900-01-01')

    WHEN ISNULL(timestamp3,'1900-01-01') >= ISNULL(timestamp1,'1900-01-01')

    AND ISNULL(timestamp3,'1900-01-01') >= ISNULL(timestamp2,'1900-01-01')

    AND ISNULL(timestamp3,'1900-01-01') >= ISNULL(timestamp4,'1900-01-01')

    THEN ISNULL(timestamp3,'1900-01-01')

    WHEN ISNULL(timestamp4,'1900-01-01') >= ISNULL(timestamp1,'1900-01-01')

    AND ISNULL(timestamp4,'1900-01-01') >= ISNULL(timestamp2,'1900-01-01')

    AND ISNULL(timestamp4,'1900-01-01') >= ISNULL(timestamp3,'1900-01-01')

    THEN ISNULL(timestamp4,'1900-01-01')

    END As MaxDate

    FROM [Dates]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!