Created
November 6, 2021 14:32
-
-
Save karthiks/c11c19b8a47046300bd4714525e1e0d1 to your computer and use it in GitHub Desktop.
Table-Valued UDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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