SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

If Exists (Select * From dbo.sysobjects where id = object_id(N'[dbo].[qryMMSGetActiveVendorEntityItemsByEntityId]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[qryMMSGetActiveVendorEntityItemsByEntityId]
GO

CREATE PROCEDURE [dbo].[qryMMSGetActiveVendorEntityItemsByEntityId]
@EntityID as bigint
AS
BEGIN

	select i.ItemCode, e.Entity, v.VendorName, vei.VendorCode, vei.VendorDescription, vei.PurchaseUnit, vei.DiscontinueDateOverridden 
from tbVendorEntityItem vei with (nolock)
join tbitem i with (nolock)
on vei.ItemID = i.ItemID
join tbentity e with (nolock)
on vei.entityid = e.entityid
join tbvendor v with (nolock)
on vei.VendorID = v.VendorID
where v.TrackPurchasesFlag = 1
 and v.VendorSince is not NULL
  and v.LocalVendor = 0 
  and vei.DiscontinueDate is NULL
and e.EntityID = @EntityID
order by e.StoreNumber, v.VendorName

END
GO