with data as ( select a.activityId, a.userName, a.eventTime, a.eventCd, b.eventDescription, a.eventDetail, a.recordDescrip, a.recordKey1, a.recordKey2, a.recordKey3, a.recordKey4 , a.formFields from tbl_TRK_LibraryActivity a with (nolock) LEFT OUTER JOIN dbo.tbl_TRK_EventCodes b with (nolock) ON (a.EventCd = b.EventCd) where RecordOwnerID = #attributes.ownerId# and RecordOwnerType = '#attributes.ownerType#' and RecordTableCd = and RecordKey1 = and RecordKey2 = and RecordKey3 = ) #forJSON( 'data', attributes.datastore, 'eventTime' )#