-----------Audit Log-----------------------------------
--select top 500 * from tbAudit
--where AuditEventID = 500
--order by 1 desc
---------------Rules-----------------------------------
Declare @VendorCode varchar(50) = '100463'
Select * from tbVendorItemEntityRule
where VendorCode = @VendorCode
--and
--VendorItemEntityRuleId = 126

select * from tbVendorItemZoneRule
where 
VendorCode = @VendorCode

-----------------Current VEI relationship------------------------------

DECLARE @EntityId bigint = 123
--DECLARE	@VendorCode varchar(50) = '100463'
select	vei.VendorDescription 
,		v.VendorName
,		vei.VendorCode
,		vei.ItemID
,		vei.EntityID
,		vei.IntroductionDate as 'VEI Intro Date'
,		vei.DiscontinueDate   as 'VEI Discontinue Date'
,		vi.IntroductionDate as 'VI Intro Date'
,		vi.DiscontinueDate as 'VI Disc Date'
,		vei.DiscontinueDateOverridden
,		vei.DiscontinueDateOverrideEnabled
,		vei.ItemID
--,		*
from	tbVendorEntityItem vei with (nolock)
join	tbVendor v with (nolock) on vei.VendorID = v.VendorID 
join	tbVendorItem vi with (nolock) on vi.VendorID = vei.VendorID and vi.VendorCode = vei.VendorCode
where vei.VendorCode = @VendorCode and  vei.entityid in(123,269)--= @EntityId 