use AlplaPROD_test1
/**

move this over to the delivery date range query once we have the shift data mapped over correctly.

update the psi stuff on this as well.
**/
declare @start_date nvarchar(30) = '[startDate]' --'2025-01-01'
declare @end_date nvarchar(30) = '[endDate]' --'2025-08-09'


select  IdArtikelVarianten, 
ArtikelVariantenBez,
sum(Menge) totalDelivered,
case when convert(time, upd_date) between '00:00' and '07:00' then convert(date, upd_date - 1) else convert(date, upd_date) end as ShippingDate

from dbo.V_LadePlanungenLadeAuftragAbruf (nolock)

where upd_date between CONVERT(datetime, @start_date + ' 7:00') and CONVERT(datetime, @end_date + ' 7:00') 
and IdArtikelVarianten in ([articles])

group by IdArtikelVarianten, upd_date,
ArtikelVariantenBez