# Need to update the query for Fiscal year weekly Report for different time of Shift

**URL:** <https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151>\
**Category:** Ignition\
**Created:** [August 26, 2024, 12:29pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151 "2024-08-26T12:29:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AkshayP](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@AkshayP](https://forum.inductiveautomation.com/u/AkshayP)\
**Post date:** [August 26, 2024, 12:29pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151/1 "2024-08-26T12:29:32Z")

</div>

Hello Team,  
We have a SQL query in place for the subject report. The query is set to grab the data from each shift (morning,afternoon,night). Each shift is for 8 hours. Now one of our line is running 10 hours afternoon shift and 7 hours night shift instead of 8 hours. Our query is grouped by 8 hours shift. I am trying to edit the query but I am not getting accurate the data for afternoon and night shift. If someone has the idea on this will really appreciate.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 26, 2024, 12:40pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151/2 "2024-08-26T12:40:23Z")

</div>

Please edit your post to remove the leading indent. That causes a quotation format that put everything on one line. I'm not going to scroll sideways through your whole question.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 26, 2024, 1:11pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151/3 "2024-08-26T13:11:59Z")

</div>

And, perhaps, share your query and what you have tried.

---

<div class="post-metadata">

**Author:** ![AkshayP](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@AkshayP](https://forum.inductiveautomation.com/u/AkshayP)\
**Post date:** [August 26, 2024, 2:22pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151/4 "2024-08-26T14:22:39Z")

</div>

Sorry for that. I changed it

---

<div class="post-metadata">

**Author:** ![AkshayP](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@AkshayP](https://forum.inductiveautomation.com/u/AkshayP)\
**Post date:** [August 27, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151/5 "2024-08-27T15:47:53Z")

</div>

@pturmel , Can you see whole topic now?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 27, 2024, 3:51pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151/6 "2024-08-27T15:51:16Z")

</div>

Yes, but I have nothing to add to what Jordan requested. We cannot read your mind or see your screen or know what you've already tried.

When answering Jordan, be _ **verbose** _.

---

<div class="post-metadata">

**Author:** ![AkshayP](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@AkshayP](https://forum.inductiveautomation.com/u/AkshayP)\
**Post date:** [August 27, 2024, 5:24pm UTC](https://forum.inductiveautomation.com/t/need-to-update-the-query-for-fiscal-year-weekly-report-for-different-time-of-shift/95151/7 "2024-08-27T17:24:00Z")

</div>

```python
select Uptime, Downtime, Stops, Efficiency, Totaltime, concat (Date,'-', case when Shift = 'Morning' then substring (shift, 1,3) when Shift = 'Afternoon' then substring (shift, 1,3) else substring(shift, 1,5) end ) as Date, tstamp, row_number() over (order by (select null)) as indx,shift, Date as date1
from
(select case when Production_Day = 1 then Uptime end as Uptime,
case when Production_Day = 1 then Downtime end as Downtime,
case when Production_Day = 1 then Stops end as Stops,
case when Production_Day = 1 then Efficiency end as Efficiency,
case when Production_Day = 1 then Totaltime end as Totaltime,
case when Production_Day = 1 then Date end as Date,
case when Production_Day = 1 then tstamp end as tstamp,Shift
from
(select cast(sum(case when Production_Day = 1 then (Bread_1hrUpTime_Minutes_History) end) as varchar(254)) as Uptime,
cast(sum(case when Production_Day = 1 then (Bread_1hrDownTime_Minutes_History) end) as varchar(254)) as Downtime,
cast(sum(case when Production_Day = 1 then (Bread_StoppageHistory) end) as varchar(254)) as Stops,
SUM(Bread_1hrTotalTime_Minutes_History) as Totaltime,
cast(Avg(case when Production_Day = 1 then (Bread_1hrEfficiency_Percentage_History) end) as varchar(254)) as Efficiency
, MAX(Current_Period) as Period , Max(Shift) as Shift, max(case when Production_Day = 1 then 1 else 0 end) as Production_Day , format((min (t_stamp)), 'MMM dd') as Date, min(t_stamp) as tstamp
FROM Fiscal_Data_Bread
WHERE Fiscal_Year = :Fiscal_Year and Current_Quarter = :Current_Quarter and Current_Period = :Current_Period and Current_Week = :Current_Week
GROUP BY DATEADD(hh, ((DATEDIFF(hh, 0, t_stamp)+2)/10*10)-2, 0)
) t
)m
where Uptime is not null

```
