SELECT 
	*
FROM (
SELECT 
		cfc.[Master],
       'Label Customer No_' = CASE cfc.[Label Customer No_] WHEN '' THEN cfc.[Customer No_] ELSE cfc.[Label Customer No_] END,
       cfi.[Item No_],
       'Description from Item' = I.[Description],
	   cfi.[Restricted Menu Item],
	   cfi.[Vending Item], 
	   cfi.[Route Item],
	   cfi.[Labeled],
	   cfi.[Inspection Legend],
   	   'Vegan'               = isnull((select [boolean value] from [Kitchen Fresh Foods$item property] where [item no_]=cfi.[Item No_] and [property code]='VEGAN'),0),
	   'Vegetarian'          = isnull((select [boolean value] from [Kitchen Fresh Foods$item property] where [item no_]=cfi.[Item No_] and [property code]='VEGETARIAN'),0),
	   'Glutenfree'          = isnull((select [boolean value] from [Kitchen Fresh Foods$item property] where [item no_]=cfi.[Item No_] and [property code]='GLUTEN FREE'),0),
	   'Lenten'              = isnull((select [boolean value] from [Kitchen Fresh Foods$item property] where [item no_]=cfi.[Item No_] and [property code]='LENTEN'),0),
	   'Pork'              = isnull((select [boolean value] from [Kitchen Fresh Foods$item property] where [item no_]=cfi.[Item No_] and [property code]='No Pork'),0),
	   'Healthy' = cfi.[Healthy Labeled],
	   'UpcCode' = cfi.[upc code],
	   'Show on menu from item' = cfi.[Show On Menu],
	   'Shelf Life (Days) from Item' = cfi.[Shelf Life (Days)],
       'Item List Code' = ISNULL(ci.[Item List Code],@ITEMLISTCODE),
   	   'Show on Menu' = ISNULL(ci.[Show on Menu],cfi.[Show On Menu]),
   	   'Shelf Life (Days)' = ISNULL(ci.[Shelf Life (days)],0),
   	   'Price Code' = ISNULL(ci.[price code],''),
   	   'Price Code Retail Value' = ISNULL(ci.[Price Code Retail Value],0),
   	   'Description Short' = ISNULL(ci.[description short],''),
   	   'Label Line 1' = ISNULL(ci.[label line 1],''),
   	   'Label Line 2' = ISNULL(ci.[label line 2],''),
   	   'Menu Section' = ISNULL(ci.[menu section],''),
   	   'User Defined Code' = ISNULL(ci.[User Defined Code],''),
   	   'Customer Item No_' = ISNULL(ci.[Customer Item No_],''),
	   
       'Base Cost' = isnull(isnull((select top 1 [Unit Price] FROM [Kitchen Fresh Foods$sales Price] WHERE [Sales Type] = 0 AND [Sales Code] = @CUSTOMER AND [Item No_] = cfi.[Item No_] AND GETDATE() BETWEEN [Starting Date] AND [Ending Date]),
		isnull((select top 1 isnull([Unit Price],0) FROM [Kitchen Fresh Foods$sales Price] WHERE [Sales Type] = 1 AND [Sales Code] = @CUSTPRICEGRP AND [Item No_] = cfi.[Item No_] AND GETDATE() BETWEEN [Starting Date] AND [Ending Date]), (select top 1 isnull([Unit Price],0) FROM [Kitchen Fresh Foods$sales Price] WHERE [Sales Type] = 1 AND [Sales Code] = 'WH' AND [Item No_] = cfi.[Item No_] AND GETDATE() BETWEEN [Starting Date] AND [Ending Date]))),'0.00'),

       'Suggested Retail Price'  = ISNULL((select top 1 isnull([Retail Price],0) FROM [Kitchen Fresh Foods$Retail Price] WHERE [Sales Type] = 1 AND [Sales Code] = @RTLPRICEGRP AND [Item No_] = cfi.[Item No_] AND GETDATE() BETWEEN [Starting Date] AND [Ending Date]),0),
	   'Authorized Menu Item' = CASE cfi.[Restricted Menu Item] WHEN 1 THEN ISNULL(ci.[Authorized Menu Item],CASE cfi.[Restricted Menu Item] WHEN 1 THEN 0 ELSE 1 END) ELSE 1 END,
	   'Custom'= cfi.[sales item description]

  FROM [Kitchen Fresh Foods$Custom Fields - Item] as cfi 
  LEFT JOIN [Kitchen Fresh Foods$Customer Items] ci on ci.[Item No_] = cfi.[Item No_] AND ci.[Customer No_] = @CUSTOMER and ci.[Item List Code] = @ITEMLISTCODE
  LEFT JOIN [Kitchen Fresh Foods$Custom Fields - Customer] cfc on cfc.[Customer No_] = @CUSTOMER 
  LEFT JOIN [Kitchen Fresh Foods$Item] I  on i.No_ = cfi.[item no_]  
  WHERE cfi.[Vending Item] = 1 and I.Blocked = 0 ) LIST  order by [Item No_] ASC