I want to have a SELECT that returns MAX(MyColumn) if something exists, otherwise return NO rows - so I can use it in a UNION:SELECT T_Sequence, [T_PrevSet] = COALESCE(T_PrevSet, 0)FROM @tabQtyBreakWHERE T_blnPriceBreakChange <> 0UNION ALL-- This to return 0 rows if ALL T_blnPriceBreakChange = 0SELECT [T_Sequence] = 999998, [T_PrevSet] = MAX(T_Sequence)FROM @tabQtyBreakWHERE T_blnPriceBreakChange <> 0UNION ALLSELECT [T_Sequence] = 999999, [T_PrevSet] = 0WHERE NOT EXISTS (SELECT * FROM @tabQtyBreak WHERE T_blnPriceBreakChange <> 0)
but it seems that the MAX(T_Sequence) select always returns a row (with a NULL if there are no matching rows) ... which means I will have to convert the whole UNION to a SUBSELECT with a WHERE to get rid of the NULL value. But maybe there is a better way?Kristen