select ready, dateReady from tbl_bcrm_objectives where objectiveid = and OwnerID = and OwnerType = update tbl_BCRM_Objectives set objName = , objDescription = , objManagerId = , objManager2Id = , objManager3Id = , publishDate = , unpublishDate = , dueDate = , territoryId = , targetType = , quotaType = , objType = , quotaDurationUnit = , totalQuota = , bundleId = , ownerRefNum = , objOwnerType = , objOwnerId = , allowFollowUpStatus = , batchQuotaSetTargetCount = , allowProtectBaseStatus = , allowRepUnenrollment = , allowRepTargeting = , salesOpsTargeting = , allowAutoTargetLinks = , limitParticipation = , ready = , dateReady = , oprDistributorRestrict = , oprTypeRestrict = , mfrOprTypeRestrict = , oprAffiliationRestrict = , oprAssignedOnlyRestrict = , unenrollmentNotifyOwner = 1 , limitAutoLinkingToTerritory = 1 , minItemCaseAmt = , minItemAnnualCaseAmt = where ownerId = and ownerType = and objectiveId = select territoryId from tbl_TER_Territories with (nolock) where ownerId = and fsl_tablecode = and territoryPath = select territoryId from tbl_TER_Territories with (nolock) where ownerId = and fsl_tablecode = and ( 1 = 2 or territoryPath = ) select t.territoryId from tbl_TER_Territories t with (nolock) inner join tbl_TER_TerritoryLevels l with (nolock) on l.levelId = t.levelId and l.ownerId = t.ownerId and l.fsl_tablecode = t.fsl_tablecode and l.brokerLevel = 1 where t.ownerId = and t.fsl_tablecode = and t.territoryPath like insert into tbl_BCRM_Objectives ( OwnerID, OwnerType, ObjName, ObjDescription, ObjType, ObjOwnerType, ObjOwnerID, OwnerRefNum, TargetType, DueDate, PublishDate, UnpublishDate, TotalQuota, QuotaType, OprDistributorRestrict, ObjPriority, ObjManagerID, ObjManager2ID, ObjManager3ID, BundleID, limitParticipation, timeframeYear, timeframePeriod, territoryid, allowAutoTargetLinks, objlevel, parentobjectiveid, teamid, oppClosedOnlyAchievement, OprAffiliationRestrict, OprTypeRestrict, QuotaDurationUnit, allowRepTargeting, salesOpsTargeting, allowFollowUpStatus, allowProtectBaseStatus, allowMultipleVisits, minItemCaseAmt, minItemAnnualCaseAmt, MfrOprTypeRestrict, ready, oppApplyToDate, dateReady, surveyId, oprAssignedOnlyRestrict, allowRepUnenrollment, unenrollmentNotifyOwner, unenrollmentApprovalRequired, batchQuotaSetTargetCount, limitAutoLinkingToTerritory) values ( , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done , -- done 'M', -- objPriority seems obsolete, M is the most common value, with space being second, check with Matt - done , -- done , -- done , -- done , -- done , -- done null, -- timeframeYear appears to be no longer used -- done null, -- timeframePeriod appears to be no longer used -- done , -- done , -- done , -- done , -- done 0, -- objTeamId is obsolete -- done 'N', -- oppClosedOnlyAchievement seems defunct - last one with a Y was in 2013 -- done , -- done , -- done , -- done , -- done , , -- done , -- done 0, -- allowMultipleVisits seems not used, no values other than zero -- done , -- done , -- done , -- done , -- done 'AD', -- oppApplyToDate seems not used, all values are AD -- done , -- done null, -- surveyId is obsolete -- done , -- done , -- done 1, -- done 0, -- unenrollmentApprovalRequired seems not used, all values are zero -- done , -- done 1 -- done ); update tbl_BCRM_Objectives set ownerRefNum = where ownerId = and ownerType = and objectiveId = select coalesce( primaryManager, 0 ) as primaryManager, coalesce( nullif( sName, '' ), name ) as shortName, internalSalesId from tbl_TER_Territories with (nolock) where ownerId = and fsl_tablecode = and territoryId = insert into tbl_BCRM_Objectives ( OwnerID, OwnerType, ObjName, ObjDescription, ObjType, ObjOwnerType, ObjOwnerID, OwnerRefNum, TargetType, DueDate, PublishDate, UnpublishDate, TotalQuota, QuotaType, OprDistributorRestrict, OprPriorityRestrict, ObjPriority, ObjManagerID, ObjManager2Id, ObjManager3Id, BundleID, limitParticipation, timeframeYear, timeframePeriod, territoryid, allowAutoTargetLinks, objlevel, parentobjectiveid, teamid, oppClosedOnlyAchievement, OprAffiliationRestrict, OprTypeRestrict, QuotaDurationUnit, allowRepTargeting, salesOpsTargeting, allowFollowUpStatus, oppApplyToDate, campaignId, MfrOprTypeRestrict, allowProtectBaseStatus, allowMultipleVisits, minItemCaseAmt, minItemAnnualCaseAmt, surveyId, oprAssignedOnlyRestrict, allowRepUnenrollment, unenrollmentNotifyOwner, unenrollmentApprovalRequired, ready, dateReady ) select OwnerID, OwnerType, as ObjName, ObjDescription, ObjType, ObjOwnerType, ObjOwnerID, OwnerRefNum, TargetType, DueDate, PublishDate, UnpublishDate, 0 TotalQuota, QuotaType, OprDistributorRestrict, OprPriorityRestrict, ObjPriority, #val( qmd_territory.primaryManager )# ObjManagerID, 0 ObjManager2ID, 0 ObjManager3ID, BundleID, limitParticipation, timeframeYear, timeframePeriod, #arguments.territoryId# territoryid, allowAutoTargetLinks, 'C' objlevel, #_saveObjective.objectiveId# parentobjectiveid, teamid, oppClosedOnlyAchievement, OprAffiliationRestrict, OprTypeRestrict, QuotaDurationUnit, allowRepTargeting, salesOpsTargeting, allowFollowUpStatus, oppApplyToDate, campaignId, MfrOprTypeRestrict, allowProtectBaseStatus, allowMultipleVisits, minItemCaseAmt, minItemAnnualCaseAmt, surveyId, oprAssignedOnlyRestrict, allowRepUnenrollment, unenrollmentNotifyOwner, unenrollmentApprovalRequired, ready, dateReady from tbl_bcrm_objectives where ownerid = and ownertype = and objectiveid = ; select linkId from tbl_bcrm_objectiveprdlink where ownerId = and ownerType = and objectiveId = and skuId = and categoryId = and mfrId = insert into tbl_bcrm_objectiveprdlink ( ownerId, ownerType, objectiveId, skuId, categoryId, mfrId ) values ( , , , , , ) delete from tbl_bcrm_objectiveprdlink where ownerId = and ownerType = and objectiveId = and linkId not in ( ) < select linkId from tbl_BCRM_ObjectiveStfLink where ownerId = and ownerType = and objectiveId = and territoryId = and fspro_userId = insert into tbl_BCRM_ObjectiveStfLink ( ownerId, ownerType, objectiveId, territoryId, fspro_userId, quota, quotaAchieved ) values ( , , , , , 0, 0 ) delete from tbl_BCRM_ObjectiveStfLink where ownerId = and ownerType = and objectiveId = and territoryId = and linkId not in ( ) <