2

I am working on another report using SSRS via Visual Studio 2010. I am a rookie with SQL but things are starting to make sense as the weeks go on.

Purpose is to create a report that displays the Batch up time / downtime calculated from the timestamps taken from a SQL server database. The time stamp is represented as a date/time input, an example, 2018-02-09 14:43:29.193.

There are 4 Event ID's 1-4 that must be met to trigger a time stamp in the database. Each batch has it's own 3 digit integer ID.

1-Batch Start, Not running production, but system is initiated. (Down)
2-Production Start, Running production (Up Time)
3-Production Stop, Machine is running, but not producing (Down)
4-Batch Stop, Production complete. (Down)

The difference between,

2&1 = Downtime
4&1 = Downtime
2&3 = Up time
If 4 is after 2 = Up time
If 4 is after 3 = Downtime

Database

I have done my best with this report with limited knowledge, and in the report I have created parameters to choose dates for the report, along with asking the user to pick the Batch ID along with Batch 1-4 Event's, however I am not sure how to tackle the calculated fields.

Below is the SQL code,

 /****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 
    [Productio_CrtNo]
  , [BatchEvent_ID]
  , [BatchEvent_TIME]
  , [Operator_ID]
  , [DieRolls_ID]
  , [Batch_ID]
  , [NoOfPockets]
  , [WetCapsulesWeight]
FROM [SCM_DataCollecion].[dbo].[ProductionTable] 

Current Report

I have been reading up on pivoting tables and I think this may be the way to go in calculated the up / downtime, however I need a bit of help on this part.

Thanks again

4

1 回答 1

0

以下是我能想到的 3 种方法来解决这个问题。

  1. 在 SQL 中使用基于 3 位 id 号的排名
  2. 根据事件 ID 在 SQL 中使用 Pivot
  3. 使用矩阵进行透视并在报告中执行计算。
于 2018-03-01T01:03:41.730 回答