Reputation: 305
I'm generating a line-shift report:
In my application, I'm providing a dropdownlist for selecting shift and line and they will select a date from calender
I have 3 shifts
I have a table called datalogging
where login information will be stored as shown below:
Name Shiftname ID operatorname Date plantname line Machine
Pradeepa Shift2(11-7) 3 Operator 3 2011-05-28 Plant 3 Line5 mc10
Ashwini Shift1(7-3) 1 Operator 1 2011-05-29 Plant 3 Line6 mc12
Deepika Shift2(11-7) 2 Operator 3 2011-05-29 Plant 5 Line9 mc18
Ashwini Shift1(7-3) 1 Operator 1 2011-05-24 Plant 1 Line1 mc1
Deepika Shift2(3-11) 2 Operator 2 2011-05-24 Plant 2 Line3 mc5
Ashwini Shift2(3-11) 1 Operator 2 2011-05-25 Plant 2 Line3 mc5
and so on..
I have a parameter table like temperature,pressure,ph,speed,co2 etc
Temperature
table contains following data and this table will contains all the reading from 7am to till 3am
Temperature Time Date
27 13:13:54.000 2011-05-25
27.3 13:14:04.000 2011-05-25
27.6 13:14:14.000 2011-05-25
27.9 13:14:24.000 2011-05-25
28.2 13:14:34.000 2011-05-25
28.5 13:14:44.000 2011-05-25
27 16:13:29.000 2011-05-26
27 16:13:31.000 2011-05-26
and so on..
The user will select a line from dropdownlist and shift and he will select a date from th calender If the user select shift2,line3 and date 25/05/2011 what are the readings are there between 3pm to 11pm should be displayed in my report
My report should look like:
Machine Shiftname Date Time Temperature
mc5 Shift2 25/05/2011 13:13:54.000 27
mc5 Shift2 25/05/2011 13:14:04.000 27.3
mc5 Shift2 25/05/2011 13:14:14.000 27.6
I'm also doing line-day report
where shiftname should change according to time for eg if time changes to 23:00:00 shiftname should change to shift3 in my report
if the user select particular shift and date for eg if the user selects shift1,line1 and date my report should contain all reading between 7am to 3pm
can any one help me on this.
Upvotes: 3
Views: 200
Reputation: 58471
You could get your report with following query
SELECT d.Machine
, CASE WHEN t.time BETWEEN '19:00:00.000' AND '23:59:59.999' THEN 'Shift1'
WHEN t.time BETWEEN '00:00:00.000' AND '02:59:59.999' THEN 'Shift1'
WHEN t.time BETWEEN '03:00:00.000' AND '10:59:59.999' THEN 'Shift2'
WHEN t.time BETWEEN '11:00:00.000' AND '18:59:59.999' THEN 'Shift3'
END
, t.Date
, t.Time
, t.Temperature
FROM Datalogging d
INNER JOIN Temperature t ON t.Date = d.Date
WHERE d.Shifname = 'Shift2(3-11)'
AND d.Line = 'Line3'
AND t.Date = '25/05/2011'
but if we can assume that each machine would have temperature readings each day, it is clear that there's a relationship missing between your Temperature
and Datalogging
table.
Upvotes: 2