CREATE TABLE EmployeesTest (
    EmpID      INT,
    EmpName    VARCHAR(100),
    Salary     DECIMAL(12,2)
);

INSERT INTO EmployeesTest VALUES (1, 'Arman', 1500);
INSERT INTO EmployeesTest VALUES (2, 'Anna', 2200);
INSERT INTO EmployeesTest VALUES (3, 'Gurgen', 1800);

--Inline Table-Valued Function (Best performance)

CREATE OR ALTER FUNCTION dbo.GetEmployees()
RETURNS TABLE
AS
RETURN
(
    SELECT EmpID, EmpName, Salary
    FROM EmployeesTest
);

SELECT * FROM dbo.GetEmployees();

------------------------------------------------
--Inline TVF with Parameter
CREATE OR ALTER FUNCTION dbo.GetEmployeesBySalary(@MinSalary DECIMAL(12,2))
RETURNS TABLE
AS
RETURN
(
    SELECT EmpID, EmpName, Salary
    FROM EmployeesTest
    WHERE Salary >= @MinSalary
);

SELECT * FROM dbo.GetEmployeesBySalary(1800);

-----------------------------------------------
/*
Multi-Statement Table-Valued Function

Use this only when you need logic (loops, conditions, merges, etc.)
It is more flexible but slower than the inline version.
*/
CREATE OR ALTER FUNCTION dbo.GetEmployeesDetailed()
RETURNS @Result TABLE
(
    EmpID      INT,
    EmpName    VARCHAR(100),
    Salary     DECIMAL(12,2),
    SalaryLevel VARCHAR(20)
)
AS
BEGIN
    INSERT INTO @Result
    SELECT 
        EmpID,
        EmpName,
        Salary,
        CASE 
            WHEN Salary >= 2000 THEN 'High'
            WHEN Salary >= 1500 THEN 'Medium'
            ELSE 'Low'
        END
    FROM EmployeesTest;

    RETURN;
END;

SELECT * FROM dbo.GetEmployeesDetailed();
