-2

I have this function in Microsoft SQL Server:

CREATE FUNCTION dbo.function_name ()
RETURNS TABLE
AS
RETURN
(
WITH cte As (
    SELECT *
    FROM TABLE
)
    SELECT column1, 1 As column_id
    FROM cte
UNION ALL
    SELECT column2, 2 As column_id
    FROM cte
)


SELECT *
FROM dbo.function_name()

After a couple of minutes I still have no output. However if I delete the UNION ALL part and select only one of those statements it works fine and quick. What do I do wrong?

Browse other questions tagged or ask your own question.