输入数据Input dataBULK INSERT #tempTblFROM 'C:\Users\MZ\data_MZ_(td).txt' 查询#tempTbl现在显示在表格中Query on #tempTbl now shows in tableSELECT * FROM #tempTbl AsAsSnoIdRSUMSUMinutesOverTimeMinutes~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~11200104305002120020444500312003102003041200420200200512005040020061200603002000712007020045681200802003456291200902003452310120100200563456 SOOPThe SOOPDECLARE @Sno INTDECLARE @Id INTDECLARE @RSUM INTDECLARE @TotalMinutes intDECLARE @OverTimeMinutes int--DECLARE sumcal CURSOR GLOBAL SCROLL DYNAMIC OPTIMISTIC FOR SELECT EmpId,Sno FROM #tempTblDECLARE sumcal CURSOR GLOBAL SCROLL DYNAMIC OPTIMISTIC FOR SELECT Id, Sno FROM #tempTblOPEN sumcalFETCH FIRST FROM sumcal INTO @Id,@Sno--FETCH FIRST FROM sumcal INTO @SnoWHILE ( @@FETCH_STATUS = 0 ) BEGIN SELECT @RSUM = SUMinutes FROM #tempTbl WHERE SNo=@Sno SELECT @TotalMinutes = SUM(SUMinutes) FROM #tempTbl WHERE Id=@Id and SNo<=@Sno IF(@TotalMinutes>2400) BEGIN IF(SELECT COUNT(*) FROM #tempTbl WHERE Id=@Id AND SNo<@Sno AND OvertimeMinutes>0)>0 BEGIN SELECT @OverTimeMinutes = SUMinutes FROM #tempTbl WHERE SNo=@Sno SET @RSUM = 0 END ELSE BEGIN SET @OverTimeMinutes = (@TotalMinutes-2400) SET @RSUM = (1000 - @OverTimeMinutes) END END ELSE BEGIN SET @OverTimeMinutes = 0 END-- Calculate Employee Overtime Hours - End UPDATE #tempTbl SET OvertimeMinutes = @OverTimeMinutes, RSUM = @RSUM WHERE SNo=@Sno SET @OverTimeMinutes = 0 SET @TotalMinutes = 0 SET @RSUM = 0 FETCH NEXT FROM sumcal INTO @Id,@Sno --FETCH NEXT FROM sumcal INTO @Sno ENDCLOSE sumcalDEALLOCATE sumcal 抓取器之后的另一个查询SELECT * FROM #tempTblAnother query after the fetcher does its thing 'SELECT * FROM #tempTbl'SnoIdRSUMSUMinutesOverTimeMinutes~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~11200143043002120024444440312003200200041200420020005120054004000612006300300071200720020008120082002000912009200200010120102002000 这可能不是OP正在寻找的输出。没有任何进一步的信息,遇到确切的错误,一些好的输出(预期的)等等,这是不可能的。This couldn't possibly be the output for which the OP is looking. Without any further information, exact errors encountered, some "good" output (expected), etc it's impossible to proceed on this matter. 这篇关于基于写集的查询/查询/子查询而不是游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-14 22:45