Snip..
WHERE (dbo.ProductIngredients.Ing_EffectiveTo =
(SELECT TOP (1) Ing_EffectiveTo
FROM dbo.ProductIngredients AS ProductIngredients_1
WHERE (Ing_Id = dbo.ProductIngredients.Ing_Id)
ORDER BY (CASE WHEN Ing_EffectiveTo IS NULL THEN '01/01/2050' ELSE Ing_EffectiveTo END) DESC))
This works fine is the from the sub where clause is not null, however when null it obviously fails unless I mess with ansi_null settings (which we wont be able to do in next version of sql server so looking for better way). How can I make this query work its like I have to change from = to IS based on the result