sql conditional union on rowcount
Posted
by Stavros
on Stack Overflow
See other posts from Stack Overflow
or by Stavros
Published on 2010-05-25T07:24:50Z
Indexed on
2010/05/25
7:31 UTC
Read the original article
Hit count: 295
sql
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
)
© Stack Overflow or respective owner