I have a simple query I use frequently to get all weightdata on a certain production line between a specific time period.
Now I want to convert the query I have to a visual studio report so other people can run the report instead of asking me.
As a first step I'm trying to run a query in management studio to see if it works.
DECLARE @ProductionLineID as int
Set @ProductionLineID = 11
DECLARE @Start as timestamp
Set @Start = '2018-06-29 19:20'
DECLARE @End as timestamp
Set @End = '2018-06-30 19:10'
SELECT [ProductionLineId]
,[Timestamp]
,[ActiveRecipe]
,[ActualWeight]
,[SetWeight]
,[SetBoxWeight]
,[SetMaxTolerance]
,[SetMinTolerance]
,[DeviationFromSetWeight]
,[AmountOfProductInBox]
,[AverageProductWeightPerBox]
,[ActualSealTemp]
,[ActualCuttingTemp]
,[ParametersChanged]
,[rejectError]
FROM [PP_Staging].[NIV].[Packaging]
where ProductionLineId = @ProductionLineID
and timestamp between @Start and @End
order by Timestamp
This results in the following error
Msg 257, Level 16, State 3, Line 5
Implicit conversion from data type varchar to timestamp is not allowed. Use the CONVERT function to run this query.
Msg 257, Level 16, State 3, Line 7
Implicit conversion from data type varchar to timestamp is not allowed. Use the CONVERT function to run this query.
So I tried the convert function on the relevant part:
DECLARE @Start as timestamp
Set @Start = convert(timestamp, '2018-06-29 19:20')
DECLARE @End as timestamp
Set @End = convert(timestamp, '2018-06-30 19:10')
Which results in
Msg 8115, Level 16, State 2, Line 9
Arithmetic overflow error converting expression to data type datetime.
So first question would be how do I input/set this parameter so I can test the report?
I know my code works if I enter it manually, so I'm basically searching for a way of converting this manual query into a report with variables. Once I have that I can try to figure out how to setup the report.
Working code sample:
SELECT [ProductionLineId]
,[Timestamp]
,[ActiveRecipe]
,[ActualWeight]
,[SetWeight]
,[SetBoxWeight]
,[SetMaxTolerance]
,[SetMinTolerance]
,[DeviationFromSetWeight]
,[AmountOfProductInBox]
,[AverageProductWeightPerBox]
,[ActualSealTemp]
,[ActualCuttingTemp]
,[ParametersChanged]
,[rejectError]
FROM [PP_Staging].[NIV].[Packaging]
where ProductionLineId = 11
and timestamp between '2018-06-29 19:20' and '2018-06-30 19:10'
order by Timestamp