declare @ownerId int = ; declare @ownertype varchar(3) = ; with data as ( select c.linkId, c.calendarId, c.calendarName, c.calendarId as id, c.calendarName as text from tbl_WRK_Calendars c where c.ownerType = @ownerType and c.ownerId = @ownerId and c.linkType = 'EVT' and #applyFilter( attributes.datastore.filter )# ) #forJSON( 'data', attributes.datastore, _defaultSortField )#