Q:

SQL: If var = '' do nothing else add a condition to a WHERE clause

I would like to perform one part of a WHERE clause on the condition that a variable has a value. I have tried writing this in many different ways but always hit an error and was wondering if someone could help.
The code below is my current SQL statement that works but will return nothing if my @itemId is empty. I would only like to reduce the results if the @itemId as a value.
DECLARE @itemId nvarchar(max)
SET @itemId = 'someId'

SELECT
SalesOrdersItems.Id,
CASE
    WHEN SalesOrderItems.ItemType = 'P' THEN Products.ProductId
    WHEN SalesOrderItems.ItemType = 'S' THEN Sundries.SundryId
    WHEN SalesOrderItems.ItemType = 'F' THEN FreightMethods.FreightMethodId
    ELSE SalesOrderItems.FreeTextItem
END AS ItemId
FROM SalesOrderItems
    LEFT OUTER JOIN Products ON SalesOrderItems.Product = Products.Product
    LEFT OUTER JOIN Sundries ON SalesOrderItems.Sundry = Sundries.Sundry
    LEFT OUTER JOIN FreightMethods ON SalesOrderItems.FreightMethod = FreightMethods.FreightMethod
WHERE 
SalesOrdersItems.area LIKE 'SE%'
AND (Products.ProductId = @itemId OR Sundries.SundryId = @itemId OR FreightMethods.FreightMethodId = @itemId OR SalesOrderItems.FreeTextItem = @itemId)

I have tried writing the last line like this(see code below) but it doesn't work.
AND CASE 
        WHEN @itemId = '' THEN 1
        ELSE (Products.ProductId = @itemId OR Sundries.SundryId = @itemId OR FreightMethods.FreightMethodId = @itemId OR SalesOrderItems.FreeTextItem = @itemId)
    END

Does anyone have any ideas where I am going wrong?

A:

If I'm misunderstanding please let me know, I'm assuming that if you have a blank @itemID you want all results, otherwise you'll limit the results.
WHERE SalesOrdersItems.area LIKE 'SE%' 
AND ((@itemId != '' 
    AND (Products.ProductId = @itemId 
         OR Sundries.SundryId = @itemId 
         OR FreightMethods.FreightMethodId = @itemId 
         OR SalesOrderItems.FreeTextItem = @itemId)) 
    OR @itemId = '')

I believe I have the parens correct, but they might be uneven. Hopefully it is it clear enough to understand my intent.

