DECLARE @ZoneId int = (select ZoneID from tbZone with (nolock) where [Zone] = 'Food Donations Pilot')

-- Strips
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '3201' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '3201'
END
-- Nuggets
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '70' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '70'
END
-- Grilled Nuggets
IF NOT EXISTS(SELECT 1 FROM tbFoodDonationItem fdi INNER JOIN tbItem i ON i.ItemID = fdi.ItemID WHERE i.ItemCode = '10681' AND fdi.ZoneID = @ZoneId)
BEGIN
   INSERT INTO [dbo].[tbFoodDonationItem] ([ItemID], [SalesItemID], [DonationUomId], [WasteUomId], [ExportUomId], [DonationToWaste], [DonationToExport], [SortOrder], [ZoneId])
   SELECT ItemID, NULL, 10, 10, 10, 1, 1, 0, @ZoneId FROM tbItem WITH (NOLOCK) WHERE ItemCode = '10681'
END

--**********************

--Minis

SELECT * FROM tbFoodDonationItem fdi with (nolock)
INNER JOIN tbSalesItem si with (nolock) 
ON si.SalesItemID = fdi.SalesItemID WHERE si.ItemCode ='10051'

SELECT * FROM tbFoodDonationItem with (nolock)
where FoodDonationItemId = 5

 SELECT * FROM tbItem WITH (NOLOCK) WHERE ItemCode = '562'
 --itemid = 623
begin tran
update tbFoodDonationItem
set SalesItemId = null, itemid=623, DonationUomId = 10, ExportUomId = 10, ExportUomId = 10
where FoodDonationItemId = 5
--commit tran
--rollback tran

begin tran
update tbFoodDonationItem
set DonationUomId = 1, ExportUomId = 1
where FoodDonationItemId = 5
--commit tran
--rollback tran
