declare @ownerId int = ; declare @ownerType varchar(3) = ; declare @endDate date = cast( getDate() as date ); with data as ( select periodName, startDate, endDate, fiscalStartMonth, fiscalEndMonth, coalesce( percentComplete, 0.0 ) as percentComplete from tbl_CRM_FiscalPeriods with (nolock) where ownerId = @ownerId and ownerType = @ownerType and startDate <= @endDate and periodType = 'M' ) #forJSON( 'data', attributes.datastore, 'endDate desc' )#