select distinct tm.teamMemberUserId, m.firstName, m.lastName from tbl_TER_TeamMembers tm inner join tbl_TER_TeamMembers mm on mm.territoryId = tm.territoryId inner join tbl_FSPRO_Members m on m.fspro_userid = tm.teamMemberUserId and m.ownerId = tm.ownerId where mm.teamMemberuserId = and tm.territoryId in ( ) and tm.ownerId = and tm.ownerType = and tm.teamMemberRole = 'TeamMember' order by lastName, firstName select distinct tm.teamMemberUserId, m.firstName, m.lastName from tbl_TER_TeamMembers tm inner join tbl_FSPRO_Members m on m.fspro_userid = tm.teamMemberUserId and m.ownerId = tm.ownerId where tm.territoryId in ( ) and tm.ownerId = and tm.ownerType = and tm.teamMemberRole = 'TeamMember' order by lastName, firstName select distinct tf.name, tf.timeframeId, tf.endDate from tbl_DW_Timeframes tf inner join tbl_DW_ScorecardFacts f on f.timeframeId = tf.timeframeId and f.subjectId in ( ) where tf.ownerId = and tf.ownerType = order by tf.endDate desc select fiscalYear, calendarMonth, endDate from tbl_DW_Timeframes tf where tf.endDate = ( select max( t.endDate ) from tbl_DW_Timeframes t inner join tbl_DW_ScorecardFacts f on f.timeframeId = t.timeframeId where t.ownerId = and t.ownerType = and f.subjectType = 'USR' and f.subjectId in ( ) ) and tf.ownerId = and tf.ownerType = select fiscalYear, calendarMonth, endDate from tbl_DW_Timeframes tf where tf.timeframeId = and tf.ownerId = and tf.ownerType = select fiscalYear, calendarMonth, startDate from tbl_DW_Timeframes where fiscalYear = and calendarMonth = and ownerId = and ownerType =
 
 
 
select #qmd_facts.columnList# from qmd_facts order by fiscalYear, calendarMonth select round( avg( f.pipelineClosedCount ), 0) pipelineClosedCount, avg( f.pipelineIdeaCount ) pipelineIdeaCount, avg( f.opportunitySaleCount ) opportunitySaleCount, avg( f.opportunityNoSaleCount ) opportunityNoSaleCount, avg( case when f.opportunityNoSaleCount > 0 or f.opportunitySaleCount > 0 then f.opportunitySaleCount / convert( float, f.opportunitySaleCount + f.opportunityNoSaleCount ) else 0.0 end ) winRate, avg( f.opportunityTimeToClose ) opportunityTimeToClose, round( avg( f.annualDollarsSold ), 0 ) annualDollarsSold, round( avg( f.opportunitySoldDollars ), 0 ) opportunitySoldDollars, round( avg( f.opportunitySoldCases ), 0 ) opportunitySoldCases, round( avg( f.opportunitySoldLbs ), 0 ) opportunitySoldLbs, avg( f.pipelineActiveCount ) pipelineActiveCount, t.startDate, t.endDate, t.fiscalYear, t.calendarMonth, t.name from tbl_DW_Timeframes t inner join tbl_DW_ScorecardFacts f on f.timeframeId = t.timeframeId where t.ownerId = and t.ownerType = and f.subjectType = 'USR' and f.subjectId in ( ) and t.startDate >= and t.endDate <= group by startDate, endDate, fiscalYear, calendarMonth, name order by fiscalYear desc, calendarMonth desc select f.pipelineClosedCount, f.pipelineIdeaCount, f.opportunitySaleCount, f.opportunityNoSaleCount, case when f.opportunityNoSaleCount > 0 or f.opportunitySaleCount > 0 then f.opportunitySaleCount / convert( float, f.opportunitySaleCount + f.opportunityNoSaleCount ) else 0.0 end winRate, f.opportunityTimeToClose, f.annualDollarsSold, f.opportunitySoldDollars, f.opportunitySoldCases, f.opportunitySoldLbs, f.pipelineActiveCount, t.startDate, t.endDate, t.fiscalYear, t.calendarMonth, t.name from tbl_DW_Timeframes t inner join tbl_DW_ScorecardFacts f on f.timeframeId = t.timeframeId where t.ownerId = and t.ownerType = and f.subjectType = 'USR' and f.subjectId in ( ) and t.startDate >= and t.endDate <= order by fiscalYear desc, calendarMonth desc