sql conditional union on rowcount
- by Stavros
I have an SQL function which returns a list of Teams.
I want to join an additional list to that list with a union, but only if it returns more than one rows.
Something like:
CREATE FUNCTION Teams()
RETURNS TABLE
AS
RETURN
(
SELECT * FROM TABLE1
UNION
if @@rowcount>1
SELECT * FROM TABLE2
end if
)