declare @datetimestart datetime
declare @TranID uniqueidentifier
--declare @RemarkDoc nvarchar(15)
set @TranID=NEWID()
--EXEC sp_PDDShowPartNGInsertERP '2018-04-20',1,'0786','578w'
-- EXEC sp_PDDShowPartNGInsertERP '2019-06-17',2,'0786','0','A0001'
declare @EndTimeNight as datetime -- variable Date End
declare @LineName as nvarchar(20)
declare @datestart as datetime
DECLARE @EndDdate datetime
DECLARE @dateinsertERP datetime
declare @strTime as nvarchar(8)
set @datetimestart='2019-06-17'
select @strTime=convert(char(8), getdate(), 108)
set @dateinsertERP= CONVERT(VARCHAR(10), @datetimestart, 111)+' '+@strTime
--select @dateinsertERP
declare @strDate nvarchar(12)
select @strDate= CONVERT(varchar(12),@datetimestart, 102)
declare @strstart as nvarchar(30)
select @strstart='2019-06-17 20:00:00.000'
SELECT convert(datetime, '2019-06-17 20:00:00.000', 120)
--select 'anight'
set @datestart=CONVERT(VARCHAR(10), @datetimestart, 111)+' 20:00:00.000'
select @EndTimeNight=DATEADD(hour,12,@datestart)--add date 12 hour
declare @begintimenight as datetime
select @begintimenight=DATEADD(hour,-12,@EndTimeNight)--add date 12 hour
select @datetimestart, @strDate,@begintimenight,@EndTimeNight
-- Begin Sub Query PartNG
SELECT ROW_NUMBER() OVER(ORDER BY RPLOG_Component) AS [Row], RPLOG_Component AS Part,'PD-ASSY2','NG' , SUM(MAC_RPLOG.RPLOG_QTY) AS QTY
,RPLOG_Problem as Problem,'566','MATCO2','MATCO2','555',@TranID,@dateinsertERP,RPLOG_StatusProblem as [Status],RPLOG_ID
--FROM MAC_RPLOG where (RPLOG_ItemAssignedDate between (SELECT convert(datetime, '2019-06-17 20:00:00.000', 120)) and @EndTimeNight)
FROM MAC_RPLOG where (RPLOG_ItemAssignedDate between '2019-06-17 20:00:00.000' and @EndTimeNight)
-- FROM MAC_RPLOG where (RPLOG_ItemAssignedDate between @strstart and @EndTimeNight)
-- FROM MAC_RPLOG where (RPLOG_ItemAssignedDate between @begintimenight and @EndTimeNight)
-- FROM MAC_RPLOG where (RPLOG_ItemAssignedDate between @datestart and @EndTimeNight)
AND (RPLOG_StatusNormal=N'UN NORMAL') and RPLOG_StatusFlag=1
--and RPLOG_Model=@Model
group by RPLOG_Component,RPLOG_StatusProblem,RPLOG_Problem,RPLOG_ID--,RPLOG_ItemAssignedDate
order by RPLOG_Component,RPLOG_StatusProblem,RPLOG_Problem