SELECT @@VERSION AS SQL_Server_Version;
SELECT LEN('Hello, World!') AS String_Length;
SELECT GETDATE() AS Current_DateTime;
SELECT SUM(Salary) AS Total_Salary FROM Employees;
SELECT SQRT(25) AS Square_Root;
SELECT Name, ROW_NUMBER() OVER (ORDER BY Salary DESC) AS Rank FROM Employees;
CREATE FUNCTION AddNumbers(@num1 INT, @num2 INT)
RETURNS INT
AS
BEGIN
RETURN @num1 + @num2;
END;
SELECT dbo.AddNumbers(5, 7) AS Sum;
CREATE FUNCTION GetEmployeesByDepartment(@deptID INT)
RETURNS TABLE
AS
RETURN (
SELECT * FROM Employees WHERE DepartmentID = @deptID
);
SELECT * FROM GetEmployeesByDepartment(1);
CREATE FUNCTION GetHighSalaryEmployees()
RETURNS @ResultTable TABLE (
EmployeeID INT,
Name NVARCHAR(50),
Salary DECIMAL(10, 2)
)
AS
BEGIN
INSERT INTO @ResultTable
SELECT EmployeeID, Name, Salary
FROM Employees
WHERE Salary > 50000;
RETURN;
END;
SELECT * FROM GetHighSalaryEmployees();