
/*
 Either associate an existing Ad Hoc Zone with a Vendor, 
 or create a new Ad Hoc Zone and associate it with a Vendor.
*/

-- 1) Enter the name of an existing zone, or enter a new zone name and the zone will be created
DECLARE @AdHocZoneName VARCHAR(100) = ''

-- 2) Enter the Vendor Id to associate with this zone
DECLARE @VendorId BIGINT = 

DECLARE @AdHocZoneTypeId INT = (select ZoneTypeId from tbZoneType where ZoneType like 'Location - Ad Hoc')
IF (@AdHocZoneTypeId IS NOT NULL AND Len(@AdHocZoneName) > 0 AND NOT EXISTS (select * from tbZone where Zone like @AdHocZoneName))
BEGIN
	INSERT INTO tbZone VALUES (@AdHocZoneName, @AdHocZoneTypeId, NULL)
END

-- Assign a vendor to the zone
DECLARE @AdHocZoneId INT = (select ZoneId from tbZone where Zone like @AdHocZoneName)

IF (@AdHocZoneId IS NOT NULL AND EXISTS (select * from tbVendor where VendorId = @VendorId))
BEGIN
	INSERT INTO tbVendorZone VALUES (@VendorId, @AdHocZoneId, GetDate(), NULL, 1)
END

-- 3) Use MMS to assign stores to the Ad Hoc Zone
