Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created November 6, 2021 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthiks/c11c19b8a47046300bd4714525e1e0d1 to your computer and use it in GitHub Desktop.
Save karthiks/c11c19b8a47046300bd4714525e1e0d1 to your computer and use it in GitHub Desktop.
Table-Valued UDF
CREATE OR ALTER FUNCTION dbo.AgeStatus
(
@AGE INT
)
RETURNS CHAR(10)
AS
BEGIN
DECLARE @status CHAR(5);
IF @AGE < 18
SET @category = 'MINOR';
ELSE
SET @category = 'MAJOR';
RETURN @status
END
/*
Now, consider a query that invokes this UDF:
SELECT NAME, dbo.AgeStatus(AGE) FROM CUSTOMER;
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment