日期:2014-05-17 浏览次数:20442 次
Set @querySql = 'Declare opr_Cursor Cursor scroll for Select Distinct Contributioner As OprID, b.EmployeeName, c.Name, c.StationID From V_IncreaseIncome_Contribution a LEFT OUTER JOIN JC_Employee b On a.Contributioner=b.EmployeeCode Or a.Contributioner=b.EmployeeName Inner Join JC_Organization c On b.OrgID=c.OrgID Where a.IsChecked=3 And a.IsDeleted=0 And a.OperateOn>=''' + CONVERT(varchar(20), @startDT) + ''' And a.OperateOn<=''' + CONVERT(varchar(20), @endDT) + ''''
if(@StationID is not null)
Begin
Set @querySql = @querySql + ' And a.CreateOrgID=' + Convert(varchar(10), @StationID) +''
End
Exec(@querySql)
Open opr_Cursor
Fetch Next From opr_Cursor into @OprID, @OprName, @OrgName1, @StationID1
while(@@Fetch_Status = 0)
Begin
Select @ATBonus=@ATBonus+ISNULL(Sum(CRewardMny), 0) From V_IncreaseIncome_Contribution Where Contributioner=@OprID And IsChecked=3 And IsDeleted=0 And OperateOn>=@startDT And OperateOn<=@endDT And IncomeType=6
Fetch Next From opr_Cursor into @OprID, @OprName, @OrgName1, @StationID1
End
Close opr_Cursor
Deallocate opr_Cursor
Set @querySql = 'Declare opr_Cursor Cursor scroll for Select Distinct Contributioner As OprID, b.EmployeeName, c.Name, c.StationID From V_IncreaseIncome_Contribution a LEFT OUTER JOIN JC_Employee b On a.Contributioner=b.EmployeeCode Or a.Contributioner=b.EmployeeName Inner Join JC_Organization c On b.OrgID=c.OrgID Where a.IsChecked=3 And a.IsDeleted=0 And a.OperateOn>=''' + CONVERT(varchar(20), @startDT) +&n