SQL Server:计算存储过程

时间:2018-05-29 08:34:58

标签: asp.net sql-server label

如何编写存储过程以返回运行总计?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[uspGetPackStatisticsPerShift]
    @ShiftStart DATETIME,
    @ShiftEnd DATETIME,
    @SeriesMasterId INT
AS
    SET NOCOUNT ON;

    --DECLARE @LogicalMachineId int
    --DECLARE @WorkCellId int

    --SELECT @LogicalMachineId = mr.LogicalMachineId, @WorkCellId = lm.WorkCellId
    --FROM Shared.dbo.MachineRegistry mr
    --INNER JOIN Shared.dbo.LogicalMachine lm on lm.Id = mr.LogicalMachineId and lm.Active=1
    --WHERE mr.Active=1 AND mr.SystemId = 'Generic' AND mr.DnsName = @MachineName 

    --IF (@WorkCellId IS NULL)
    --BEGIN
    --  RAISERROR('uspGetBuildStatisticsPerShift() Workstation not defined', 15, 1)
    --  RETURN
    --END

    -- Now get the data
    SELECT
        DATEDIFF(hour, @ShiftStart, psh.DtTmEnd) + 1  AS ShiftHour,
        ifsm.[Id] AS FrameSizeMasterId,
        COUNT(ph.Id) AS TotalPacked
    FROM
        Production.dbo.PackHistory ph
    INNER JOIN 
        Production.dbo.PackStageHistory psh ON psh.PackHistoryId = ph.Id 
                                            AND psh.PackScheduleStageID = 2
    INNER JOIN 
        Production.dbo.ItemSerialNumber isn ON isn.Id = ph.ItemSerialNumberId
    INNER JOIN 
        Production.dbo.ItemMaster im ON im.Id = isn.ItemMasterId
    INNER JOIN 
        Production.dbo.ItemSeriesMaster ism ON ism.Id = im.SeriesMasterId 
                                            AND im.SeriesMasterId =  @SeriesMasterId
    INNER JOIN 
        Production.dbo.ItemFrameSizeMaster ifsm ON ifsm.Id = im.FrameSizeMasterId
    WHERE
        psh.DtTmEnd BETWEEN @ShiftStart AND @ShiftEnd 
        AND psh.Successful = 1 
        AND psh.ReRun = 0
    GROUP BY
        DATEDIFF(hour, @ShiftStart, psh.DtTmEnd) + 1, ifsm.[Id]   
    ORDER BY
        1     

此存储过程返回每班次打包的单位总数。我需要的是一个存储过程,它将返回打包为运行总计的总单位。

最后我有一个标签,我想将此值传递给..如何在每个单元打包后更新标签?我已经让我的页面在1分钟后刷新以反映更改但不确定如何将存储过程添加到aspx c中的标签#

这就是我的存储过程输出https://ibb.co/jOEkfy

现在我需要将这些值传递给aspx标签,然后在8小时后重置。

0 个答案:

没有答案