帆软支不支持批处理SQL

通过存储过程查询的SQL,数据库设计器可以执行。帆软不支持调用,有没有遇到类似问题的小伙伴


存储过程

proc_production

USE [KQMESDB]
GO

/****** Object:  StoredProcedure [dbo].[proc_production]    Script Date: 2020/10/17 11:57:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


ALTER proc [dbo].[proc_production]
as
declare @start datetime = '2020-09-16 08:00',@end datetime = '2020-09-16 18:00'
declare @step int = 2;
-------------------------------------------------------
declare @dates table(	
	sDate datetime,	
	eDate datetime
)

declare @curDate datetime = @start;

while(@curDate < @end)
begin
	insert into @dates 
		select @curDate,
		case when 
			@end > DATEADD(hour,@step,@curDate) 
		then  
			DATEADD(hour,@step,@curDate) 
		else 
			@end 
		end 
	
	set @curDate = DATEADD(hour,@step,@curDate) 
end

--select * from @dates


select
	rt.* 
	into #Routes
from ProductionTaskSheetMlotRouteEntities rt 
where
rt.PassQuantity > 0 and
exists(
	select * from ProductionTaskSheetMlotRouteFinishRecordEntities ft where
		ft.ProductionTaskSheetMlotRouteId = rt.Id and
		ft.CRDT between @start and @end 
) and
exists(
	select * from ProductionTaskSheetMlotEntities mt where
		mt.id = rt.ProductionTaskSheetMlotId and 
		exists(
			select * from ProductionTaskSheetEntities tt where 
				tt.id = mt.ProductionTaskSheetId and 
				exists(
					select * from ProductionOrderDetailEntities dt where
						dt.id = tt.ProductionOrderDetailId and
						exists(
							select * from ProductionOrderEntities pt where 
								pt.id = dt.OrderId and
								exists( 
									select * from Tfbase043300 lt where
										lt.Id = pt.ProductLineId and
										exists(
											select * from tfbase008300 mate where
												mate.id = pt.MaterialId and
												mate.PRST = 2
										)
								)
						)
				)
		)
	)



;with inQty as (
	select 
		a.logDate
	from #Routes zt
	outer apply(
		select max(a.CRDT) logDate from ProductionTaskSheetMlotRouteFinishRecordEntities a where a.ProductionTaskSheetMlotRouteId = zt.id
	) a
	where 
	zt.[Sequence] = 1
),
outQty as (
	select 
		a.logDate,zt.*
	from #Routes zt
	outer apply(
		select max(a.CRDT) logDate from ProductionTaskSheetMlotRouteFinishRecordEntities a where a.ProductionTaskSheetMlotRouteId = zt.id
	) a
	where 
		 not exists(
			select * from ProductionTaskSheetMlotRouteEntities rt where 
				zt.ProductionTaskSheetMlotId = rt.ProductionTaskSheetMlotId and 
				zt.[Sequence] < rt.[Sequence]
		)
) 
select 
	zt.sDate as [开始时间],
	zt.eDate as [结束时间],
	(
		select count(*) from inQty a where a.logDate between zt.sDate and zt.eDate
	) as [投入数],
	(
		select count(*) from outQty a where a.logDate between zt.sDate and zt.eDate
	) as [产量]
from @dates zt

drop table #Routes



--exec proc_production
GO

错误信息

image.png

yangsenyu-FR 发布于 2020-10-17 09:49 (编辑于 2020-10-17 11:59)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
yangsenyu-FRLv4见习互助
发布于2020-10-17 12:51
通过自定义函数,解决问题
最佳回答
0
snrtuemcLv8专家互助
发布于2020-10-17 10:18

换个解决方案,写bat文件,然后电脑定时调度把

最佳回答
0
luojian0323Lv7资深互助
发布于2020-10-17 10:21

批处理是系统干的事

写bat文件可实现

用python等可实现文件调度

帆软没有文件调度权限

  • yangsenyu-FR yangsenyu-FR(提问者) 问题已完善
    2020-10-17 12:09 
  • luojian0323 luojian0323 回复 yangsenyu-FR(提问者) 存储过程数据集:https://help.fanruan.com/finereport/doc-view-117.html?source=4
    2020-10-17 12:26 
  • 2关注人数
  • 389浏览人数
  • 最后回答于:2020-10-17 12:51
    请选择关闭问题的原因
    确定 取消
    返回顶部