select distinct cho_id, operatorName, ( select purchasingMonth, sku, cases from [tmp_mwgTesting] x with (nolock) where x.cho_id = oa.cho_id order by purchasingMonth for json auto ) as purchasing from [tmp_mwgTesting] oa with (nolock) order by operatorName for json auto select top 1 sku_id, sku, prod_id, product, prod_description, mfr_id, mfr_name, json_query( images ) images from tmp_junk_mwg where images is not null for json auto insert into tbl_RPT_Exports ( ownerId, ownerType, sourceSQL, linkType, linkId, createTime, status, statusTime, statusEx, fileName, fileFormat ) values ( 387, 'BRO', , '', -1, getDate(), '?', getDate(), '', 'E:\FSLContent\staging\BRO387\reports\rawJSON.txt', 'JSON' ), ( 387, 'BRO', , '', -1, getDate(), '?', getDate(), '', 'E:\FSLContent\staging\BRO387\reports\formattedJSON.txt', 'JSONF' ), ( 387, 'BRO', , '', -1, getDate(), '?', getDate(), '', 'E:\FSLContent\staging\BRO387\reports\rawJSON.zip', 'JSON' ), ( 387, 'BRO', , '', -1, getDate(), '?', getDate(), '', 'E:\FSLContent\staging\BRO387\reports\formattedJSON.zip', 'JSONF' )