SELECT	Top 10 *
FROM	tbVendorItem with (nolock)
------------------------------------------------------------------------------------
--Supplier associated with Vendor Zone

select   v.Vendorid
,		 v.VendorName as Supplier
,		 v.VendorZoneId
,		 z.Zone
--,		 *
from tbVendor v
left join tbZone z on v.VendorZoneId = z.ZoneID
where 
v.VendorZoneId is NOT NULL
------------------------LOCATION RULE ------------------------------------
DECLARE @VendorCode  varchar(50) = '009961'
SELECT	vi.VendorDescription
,		v.VendorName
,		e.Entity
,		vi.VendorCode
,		vier.RuleType
,		vier.ActiveDate as 'Start Date'
,		vier.ExpirationDate as 'End Date'
,		vier.UpdatedBy
,		vier.UpdatedDate
,		vier.Deleted
--,		*
FROM	tbVendorItemEntityRule vier with (nolock)
JOIN	tbVendorItem vi with (nolock) on vi.VendorCode = vier.VendorCode
JOIN	tbVendor v with (nolock) on vi.VendorID = v.VendorID
JOIN	tbEntity e with (nolock) on vier.Entityid = e.entityid
WHERE vier.Deleted = 0
AND vi.VendorCode = @VendorCode

----------------------LOCATION RULE APPLIED?-------------------------------------

SELECT	vi.VendorDescription
,		v.VendorName
,		*
FROM	tbVendorItemEntityRule vier with (nolock)
JOIN	tbVendorItem vi with (nolock) on vi.VendorCode = vier.VendorCode
JOIN	tbVendor v with (nolock) on vi.VendorID = v.VendorID
WHERE vi.VendorCode = '009961'

-------------------------ZONE RULE --------------------------------------
SELECT	vi.VendorDescription
,		v.VendorName
,		zt.ZoneType
,		z.Zone
,		vi.VendorCode
,		vizr.RuleType
,		vizr.ActiveDate as 'Start Date'
,		vizr.ExpirationDate as 'End Date'
,		vizr.UpdatedBy
,		vizr.UpdatedDate
--,		*
FROM	tbVendorItemZoneRule vizr with (nolock)
JOIN	tbVendorItem vi with (nolock) on vizr.VendorCode = vi.VendorCode
JOIN	tbVendor v with (nolock) on vi.VendorID = v.VendorID
JOIN	tbZone z with (nolock) on vizr.ZoneID = z.ZoneID AND vizr.ZoneTypeID = z.ZoneTypeId
JOIN	tbZoneType zt with (nolock) on vizr.ZoneTypeID = zt.ZoneTypeId
WHERE vizr.Deleted = 1 
AND	vi.VendorCode = '043514'

----------------------------ZONE RULE APPLIED?-----------------------------------------
SELECT	vi.VendorDescription
,		v.VendorName
,		*
FROM	tbVendorItemZoneRuleNew vizrn with (nolock)
LEFT JOIN	tbVendorItem vi with (nolock) on vizrn.VendorCode = vi.VendorCode
JOIN	tbVendor v with (nolock) on vi.VendorID = v.VendorID
--WHERE vi.VendorCode = '101444'

------------------------------------------------------------------------------------

--SP_HELP tbVendorItem
--SP_HELP tbVendorItemEntityRule
--SP_HELP tbVendorItemEntityRuleNew
--SP_HELP tbVendorItemZoneRule
--SP_HELP tbVendorItemZoneRuleNew



