077 User Defined Functions

SQL

CREATE FUNCTION GetFullName(
    @firstName nvarchar(50),
    @lastName nvarchar(50)
)
RETURNS nvarchar(100)
AS
BEGIN
    
    RETURN @firstName + ' ' + @lastName

END


select 
    dbo.GetFullName(firstName,lastName) as FullName,
    Performance
FROM Sales

-----------------------------------------------------------------------------

CREATE FUNCTION GetExPensiveProducts(
    @price DECIMAL(18,2)
)
RETURNS TABLE
AS
RETURN
(
    SELECT ProductId, Name, Price
    FROM Products
    where Price > @price
)

select *
from dbo.GetExPensiveProducts(0)

猜你喜欢

转载自blog.csdn.net/KevinHuang2088/article/details/143415851