• This simple sample should get you started. Have a play, explain if it doesn't meet your requirements.

    CREATE FUNCTION [dbo].[MyFirstITVF]

    (

    @StartNum INT

    )

    RETURNS TABLE WITH SCHEMABINDING AS

    RETURN

    SELECT d.MyInt, x.MyString

    FROM

    (SELECT MyInt = @StartNum + 1 UNION ALL

    SELECT MyInt = @StartNum + 2 UNION ALL

    SELECT MyInt = @StartNum + 3 UNION ALL

    SELECT MyInt = @StartNum + 4) d

    CROSS APPLY (SELECT MyString = CASE WHEN d.MyInt%2 = 1 THEN 'Odd' ELSE 'Even' END) x

    GO

    SELECT * FROM [dbo].[MyFirstITVF] (0)

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden