title: Error message - Incorrect syntax near the keyword 'OR'
body: <p>My procedure is failing with the following error </p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Procedure  Line 11<br>
    Incorrect syntax near the keyword 'OR'</p>
  </blockquote>
  
  <p>The procedure is:</p>
  
  <pre><code>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'
  </code></pre>