I have a SQL command that in the SELECT there is a case that uses a value from a table or just uses '0'.

I want to use that 'cased' value in the where clause later but it's not working as I want.

Here's what I mean:

```
SELECT DISTINCT
    hi.SKUNo [HostSKU] ,
    SUBSTRING(vi.GTIN, 3, 14) [GTIN] ,
    CASE vg.VendorGroup
      WHEN vg.VendorGroup THEN vg.VendorGroup
      ELSE v.VendorNo
    END [VendorNo] ,
    'Inv_Full_Sync' [Reason Code] ,
    'Vendor Inventory Full Sync' [Reason Text] ,
    CASE vi.EncodeData
      WHEN 'Y' THEN ii.Quantity1
      ELSE 0
    END [Quantity] , --< quantity
    'ONHAND' [OnHand] ,
    RTRIM(v.Category) [Vendor Category]
FROM    ItemInventory ii
    INNER JOIN HostItems hi ON hi.ItemId = ii.ItemId
    INNER JOIN VendorItems vi ON vi.ItemId = ii.ItemId
                                 AND vi.VendorNo = ii.VendorNo
    INNER JOIN Vendors v ON v.VendorNo = ii.VendorNo
    LEFT JOIN dbo.VendorGroups vg ON vg.VendorNo = v.VendorNo
WHERE   QtyType = 0
    AND [Quantity] > 0 --< here is where it bombs..
ORDER BY VendorNo ,
    hi.SKUNo; 

```