一个存储过程的问题,很郁闷。有谁知道为什么吗?(50分)

  • 主题发起人 主题发起人 JasonLaw
  • 开始时间 开始时间
J

JasonLaw

Unregistered / Unconfirmed
GUEST, unregistred user!
要有图才能说明。这里放不到图(好象,至少我找不到文件插图进来)

我将问题放在 DELPHI盒子了。

http://bbs.2ccc.com/topic.asp?topicid=311789

存储过程是:


CREATE PROCEDURE [Gen_Stat_Table]
(@StartDate datetime,
@EndDate datetime,
@TeamMgrNo Varchar(100),
@LoginID varchar(20)) --此信息为软件登录时,登录者的ID,用此来创建 临时表
AS
declare @ss varchar(100) ,@sqlstr varchar(2500),@TmpTableName varchar(20),@DeleteTempTable varchar(30)

set @TmpTableName = '##'+@LoginID
set @DeleteTempTable =' DROP TABLE '+ @TmpTableName

IF OBJECT_ID('tempdb..'+@TmpTableName) IS NOT NULL exec(@DeleteTempTable)

--drop table #StatTmp

--if @TeamMgrNo =''
-- set @ss=''
--else
-- set @ss=' and tHandWorkDayReport.fTeamMgrNo = ' +@TeamMgrNo +''

set @sqlstr=' SELECT tHandWorkDayReport.*,tHandWorkSubDayReport.fTimeWork,
(SELECT SUM(fFinishedCount) FROM tHandWorkSubDayReport WHERE tHandWorkSubDayReport.fDayID = tHandWorkDayReport.fDayID) AS DayFinishedCount,
(SELECT SUM(fFactFinishedQty) FROM tHandWorkSubDayReport WHERE tHandWorkSubDayReport.fDayID = tHandWorkDayReport.fDayID) AS DayFactFinishedQty,
(SELECT COUNT(fWorkerNo) FROM tHandWorkSubDayReport WHERE tHandWorkSubDayReport.fDayID = tHandWorkDayReport.fDayID) AS WorkerCount,
(SELECT SUM(fManHour) FROM tHandWorkSubDayReport WHERE tHandWorkSubDayReport.fDayID = tHandWorkDayReport.fDayID) AS TotalManHour, CONVERT(decimal(10, 2),
(SELECT SUM(fFinishedCount) FROM tHandWorkSubDayReport WHERE tHandWorkSubDayReport.fDayID = tHandWorkDayReport.fDayID) /
case( (SELECT SUM(fManHour) FROM tHandWorkSubDayReport WHERE tHandWorkSubDayReport.fDayID = tHandWorkDayReport.fDayID)) when 0 then 1 end) AS FaceTarget, CONVERT(decimal(10, 2),
tHandWorkSubDayReport.fFinishedCount / case( tHandWorkSubDayReport.fManHour) when 0 then 1 end) AS FactTarget,tHandWorkSubDayReport.fWorkerNo,
tHandWorkSubDayReport.fWorkerName,
tHandWorkSubDayReport.fStartTime,
tHandWorkSubDayReport.fEndTime,
tHandWorkSubDayReport.fManHour,
tHandWorkSubDayReport.fFinishedCount,
tHandWorkSubDayReport.fFactFinishedQty,
tHandWorkSubDayReport.fID
INTO '+@TmpTableName+'
FROM tHandWorkDayReport INNER JOIN
tHandWorkSubDayReport ON
tHandWorkDayReport.fDayID = tHandWorkSubDayReport.fDayID
Where tHandWorkDayReport.fDate between '''+convert(varchar(10),@StartDate,120) +''' and '''+convert(varchar(10), @EndDate,120) +'''' + @TeamMgrNo

exec(@sqlstr)
GO
 
干吗 不 连接 + group
 
你的存储过程内容呢?
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
933
SUNSTONE的Delphi笔记
S
C
回复
3
查看
749
cncangel
C
后退
顶部