我的过程失败,并显示以下错误
第156条消息,状态1,状态1,程序行11
关键字“ OR”附近的语法不正确
过程是:
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[JobsStatusView]'))
EXEC dbo.sp_executesql @statement = N'DROP view [dbo].[JobsStatusView]'
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW JobsStatusView AS
SELECT AL.MAC,AL.AssemblyLineId,
AL.Name as AssemblyName,AL.SiteId,AL.IsActive,AL.IsRegistered,AL.IsOnline,
JB.Name as JobName,JB.Goal,JB.[Status],JB.Id as JobId,Jb.StartTime as JobStartTime,JB.Endtime as JobEndTime,JB.JobType,JB.Id as jobtypeid,
PT.Id as PartId,PT.[SKU] As PartSKU,PT.[Name] As PartName,JB.TargetCycleTime,PT.EquipmentCycleTime,JB.SlowCycleLimit,JB.SmallStopLimit,JB.BreakDownLimit,PT.Material,PT.GoodPartScaleFactor,PT.RejectionScaleFactor,
PT.CompanyId,
(select count(eventid) from EventStreams es where es.jobid=jb.id and es.EventType=''Pulse'') as GoodCount,
(select count(eventid) from EventStreams es where es.jobid=jb.id and es.EventType=''RejectionPulse'') as RejectedCount,
(select count(eventid) from EventStreams es where es.jobid=jb.id and es.EventType=''JobBreakDown'') as DownTimeCount,
sm.Machine_Id,sm.Station_Id,OR.Id as OrderId,OR.CustomerId as CustomerId,OR.ProductId as ProductId,OR.DeliveryDate as DeliveryDate,OR.Quantity as Quantity
from Jobs JB
inner join AssemblyLines AL on JB.AssemblyLineId = AL.AssemblyLineId
Inner Join Sites S on AL.SiteId= s.Id
left Join Machines m on AL.AssemblyLineId =m.AssemblyLineId
left Join StationMachines sm on m.Id = sm.Machine_Id
Inner Join parts PT on JB.PartId = PT.Id
left Join Orders OR on JB.OrderId=OR.Id'