Microsoft SQL - How to merge when certain values match Here is the database's structure:

^ Table:  Response_Master_Incident      ^
| ID                     | int          |
| Master_Incident_Number | varchar(20)  |
| Time_CallEnteredQueue  | datetime     |
| Time_CallClosed        | datetime     |
| Jurisdiction           | varchar(30)  |
| Response_Area          | varchar(30)  |
| Priority_Description   | varchar(30)  |
| Address                | varchar(400) |
| Apartment              | varchar(10)  |
| City                   | varchar(35)  |
| State                  | varchar(5)   |
| Postal_Code            | varchar(10)  |
| Call_Disposition       | varchar(30)  |
| Response_Date          | datetime     |
| Problem                | varchar(30)  |

^ Table:  Activity_Log                  ^
| ID                     | bigint       |
| Radio_Code             | varchar(20)  |
| Activity               | varchar(40)  |
| Date_Time              | datetime     |
| Master_Incident_ID     | int          |

^ Table: Case                           ^
| MasterIncidentID       | int          |
| CaseNumber             | varchar(20)  |


Here is my query currently:

DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)

SELECT Response_Master_Incident.Master_Incident_Number
  ,Response_Master_Incident.Problem
  ,CaseNumber.CaseNumber
  ,Response_Master_Incident.Time_CallEnteredQueue
  ,Response_Master_Incident.Time_CallClosed
  ,Response_Master_Incident.Jurisdiction
  ,Response_Master_Incident.Response_Area
  ,Response_Master_Incident.Priority_Description
  ,CONCAT (Response_Master_Incident.Address, ' ', Response_Master_Incident.Apartment, @NewLineChar, Response_Master_Incident.City, ', ', Response_Master_Incident.[State], '  ', Response_Master_Incident.Postal_Code) AS Full_Address
  ,Response_Master_Incident.Call_Disposition
  ,Activity_Log.Radio_Code
  ,Activity_Log.Activity
  ,Response_Master_Incident.Response_Date
  ,Activity_Log.Date_Time
  ,JurisdictionName
  ,CASE WHEN Activity_Log.Activity = 'Available' THEN 0
    WHEN Activity_Log.Activity = 'Terminated' THEN 0
    ELSE DATEDIFF(SECOND, (Activity_Log.Date_Time), (LEAD(Activity_Log.Date_Time, 1, 0) OVER (ORDER BY Response_Master_Incident.ID, Radio_Code, Activity_Log.ID))) END AS Seconds_In_Status
FROM
  Response_Master_Incident
  LEFT JOIN Activity_Log
    ON Response_Master_Incident.ID = Activity_Log.Master_Incident_ID
  LEFT JOIN Status
    ON Activity_Log.Activity = Status.Description
  LEFT JOIN CaseNumber
    ON Response_Master_Incident.ID = CaseNumber.MasterIncidentID

WHERE
  (Activity_Log.Radio_Name LIKE '[0-9][0-9][0-9][0-9]LM')
  AND Activity_Log.Radio_Code IS NOT NULL
  AND Response_Master_Incident.Response_Date BETWEEN '2016-09-01' and '2016-09-30'
  AND ((JurisdictionName = 'SomeJurisdiction') OR (JurisdictionName IS NULL))

ORDER BY Response_Master_Incident.ID,
Radio_Code,
Activity_Log.ID


So I'm querying another table using a key on the CaseNumber table, but I want the results returned in one row, concatenated.

For example, the following result:

^ Master_Incident_Number ^ CaseNumber ^ Radio_Code ^ Activity  ^ JurisdictionName ^
| 0000-000-000001        | 16-000001  | 1000PD     | Activity1 | SomeJurisdiction |
| 0000-000-000001        | 16-000002  | 1000PD     | Activity1 | SomeJurisdiction |
| 0000-000-000001        | 16-000001  | 1000PD     | Activity2 | SomeJurisdiction |
| 0000-000-000001        | 16-000002  | 1000PD     | Activity2 | SomeJurisdiction |


Would become:

^ Master_Incident_Number ^ CaseNumber            ^ Radio_Code ^ Activity  ^ JurisdictionName ^
| 0000-000-000001        | 16-000001, 16-000002 | 1000PD     | Activity1 | SomeJurisdiction |
| 0000-000-000001        | 16-000001, 16-000002 | 1000PD     | Activity2 | SomeJurisdiction |
You need to use the SQL equivalent of GROUP_CONCAT to achieve this result. 

Please see this stack overflow answer

You could also use the CROSS APPLY method from that query. 

I wrote an example using your query above. In your case, you will want to add this subquery:

SELECT STUFF((SELECT ',' + c.CaseNumber
             FROM CaseNumber as c
             WHERE Response_Master_Incident.ID = c.MasterIncidentID
             FOR XML PATH (''))
             , 1, 1, '')