• kylemkr85 (2/8/2013)


    Thanks for the quick response, however, I am receiving the following error below:

    Msg 145, Level 15, State 1, Line 1

    ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

    Oh well, you get what you get when you don't provide DDL, sample data, and expected results. No tested code.

    For better answers to your questions, please read and follow the instructions in the first article you will find referenced in my signature block below.

    Now, how about this:

    WITH BaseData AS (

    SELECT DISTINCT

    wcv.contact_name

    ,wcv.contact_organization_name

    ,wcv.workitem_title

    ,wcv.workitem_number

    ,wcv.workitem_created_on

    ,wcv.assigned_to_worker_name [Assigned To]

    ,datediff(d, workitem_created_on, getdate()) [Ticket Age]

    FROM

    contact_view cv

    JOIN workitem_current_view wcv

    ON cv.contact_email = wcv.contact_email

    WHERE

    wcv.workitem_status_lookup_value = 'Open' and

    wcv.workitem_created_on > '2006-01-01 12:00:00.000'

    )

    SELECT

    contact_name,

    contact_organization_name,

    workitem_title,

    workitem_number,

    workitem_created_on,

    [Assigned To],

    [Ticket Age]

    FROM

    BaseData

    ORDER BY

    CASE WHEN [Assigned To] = 'Group 1' THEN 0 ELSE 1 END ASC,

    [Ticket Age] DESC