emailCampaigns log {ts '2025-05-22 12:35:59'} SQL declare @ownerId int = 2252 ; declare @ownerType varchar(3) = 'MFR' ; with data as ( select e.campaignId, dbo.fseToken( e.campaignId ) as campaignTk, e.name as campaignName, e.campaignType, e.emailSubject, e.emailFromDisplay, e.emailFrom, cast( case when coalesce( e.scheduled, 'N' ) = 'Y' then 1 else 0 end as bit ) scheduled, e.useInternalContact, e.runDate, e.includeUnsubscribe, e.statusCd, e.timeReminded, e.timeStarted, e.timeCompleted, e.creator_typ, e.message1Default, e.message2Default, e.lastUpdatedDate, e.createDate, e.emailManagerVersion, e.emailEditorType, e.eai_batchId, dbo.fseToken( e.eai_batchId ) as eai_batchTk, e.creator_member_id, e.targetListId, e.updateUserId, e.responderListId, e.formResponderListId, case when e.statusCd = 'PEN' then 'Pending' when e.statusCd = 'RUN' then 'Running' when e.statusCd = 'ABT' then 'Aborted' when e.statusCd = 'SUC' then 'Executed' else 'Unknown' end as status, case when e.scheduled = 'N' then 'Not Scheduled' else case when e.statusCd = 'PEN' then 'Scheduled for Future Date/Time' when e.statusCd = 'RUN' then 'Currently Running' when e.statusCd = 'ABT' then 'Executed Unsuccessfuly' when e.statusCd = 'SUC' then 'Executed Successfully' else 'Unknown' end end as statusLong, m.campaignId gtmCampaignId, m.campaignName gtmCampaignName from tbl_EML_Campaign e with (nolock) left outer join tbl_GTM_Campaigns m with (nolock) on m.ownerId = e.ownerId and m.ownerType = e.fsl_tablecode and m.campaignId = e.gtmCampaignId where e.ownerId = @ownerId and e.fsl_tablecode = @ownerType and e.emailManagerVersion = '2.0' and e.emailEditorType = 'BEE' ) , data_mappedData as ( select * from data ) , data_preData as ( select * from data_mappedData with (nolock) where ( 1 = 1 ) ) , data_data as ( select * from data_preData ) , data_return as ( select * from data_data where 1 = 1 order by campaignName offset 0 rows fetch next 10000000 rows only ) , data_result as ( select ( select count(*) from data_data ) as totalCount, ( select * from data_return for json auto, include_null_values ) as data ) select * from data_result for JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER