attrs = StructNew();
attrs.ownerId = 1;
attrs.ownerType = "MFR";
attrs.surveyRole = 'SALESCALL';
attrs.datasource="FSLibrary";
attrs.queryName="qmd_matchingSurveySubjects";
attrs.answer = ArrayNew(1);
attrs.answer[1] = StructNew();
/*
attrs.marketingActivityId = 1021;
attrs.answer[1].questionId = 546;
attrs.answer[1].choiceId = "806,763,764";
fileName = "one-touch-ti-will-buy.xls";
*/
/*
attrs.marketingActivityId = 1021;
attrs.answer[1].questionId = 553;
attrs.answer[1].choiceId = "837";
fileName = "one-touch-ti-using-aerosol.xls";
*/
attrs.marketingActivityId = 1034;
attrs.answer[1].questionId = 581;
attrs.answer[1].choiceId = "972,973,974";
fileName = "biscuit-will-buy.xls";
/*
attrs.marketingActivityId = 1034;
attrs.answer[1].questionId = 581;
attrs.answer[1].choiceId = "1687";
fileName = "biscuit-will-not-buy.xls";
*/
/*
attrs.marketingActivityId = 1042;
attrs.answer[1].questionId = 636;
attrs.answer[1].choiceId = "1198";
fileName = "usfs-buying-aerosol.xls";
*/
/*
attrs.marketingActivityId = 1042;
attrs.answer[1].questionId = 638;
attrs.answer[1].choiceId = "1210";
fileName = "usfs-purchase-scenario-new-customer.xls";
*/
/*
attrs.marketingActivityId = 1042;
attrs.answer[1].questionId = 638;
attrs.answer[1].choiceId = "1211,1212,1213,1214";
fileName = "usfs-purchase-scenario-not-buying.xls";
*/
select opr.companyName, opr.focusAccount, ter.name, cdr.cdr_dstName
from tbl_OPR_ClientOperators opr
inner join tbl_TER_Territories ter
on ter.territoryId = opr.territoryId
and ter.ownerId = opr.ownerId
and ter.fsl_tablecode = opr.fsltablecode
left outer join tbl_CDR_Distributors cdr
on cdr.cdr_recordId = opr.distrib1
and cdr.ownerId = opr.ownerId
and cdr.fsl_tablecode = opr.fsltablecode
where opr.operatorId in ()
order by ter.name, opr.companyName