declare @EntityId bigint = 269 
 
  select 
      ez.EntityID as EntityId,
      vizr.VendorCode As VendorCode,
	  'ZoneRule' As RuleTypes,
	  vizr.ZoneId As ZoneId,
	  vi.VendorId,
      vi.ItemID,
	  vi.VendorDescription,
	  vizr.RuleType, 
	  vizr.ActiveDate, 
	  vizr.ExpirationDate, 
	  vizr.UpdatedDate, 
	  vizr.UpdatedBy, 
	  vizr.ApplyDate
  from tbVendorItemZoneRule vizr with (nolock)  
	  inner join tbEntityZone ez with (nolock) on vizr.ZoneId= ez.ZoneID 
	  inner join tbVendorItem vi with (nolock) on vi.VendorCode = vizr.VendorCode
  where 
	  ez.EntityID = @EntityId 
	  and vizr.Deleted = 0
  UNION ALL 
  select 
      vier.EntityId as EntityId,
      vier.VendorCode,
	  'EntityRule' As RuleTypes,
	  NULL As ZoneId,
	  vi.VendorID,
	  vi.ItemID,
	  vi.VendorDescription,
	  vier.RuleType, 
	  vier.ActiveDate, 
	  vier.ExpirationDate, 
	  vier.UpdatedDate, 
	  vier.UpdatedBy, 
	  vier.ApplyDate
  from tbVendorItemEntityRule vier with (nolock)   
	 inner join tbVendorItem vi with (nolock) on vi.VendorCode = vier.VendorCode
  where 
	  vier.EntityID = @EntityId 
	  and vier.Deleted = 0
  order by VendorCode, RuleTypes, ZoneID, VendorID, ItemID 