Created
November 15, 2023 12:12
-
-
Save adgedenkers/c8c778f32f38e0b9cd9275487a240016 to your computer and use it in GitHub Desktop.
This file contains 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 PROCEDURE GetTeamNameOrAbbreviation | |
@team NVARCHAR(255), | |
@slot INT | |
AS | |
BEGIN | |
IF @slot = 0 | |
BEGIN | |
-- Extract and return the part before the parentheses | |
RETURN LEFT(@team, CHARINDEX(' (', @team) - 1) | |
END | |
ELSE IF @slot = 1 | |
BEGIN | |
-- Extract and return the part inside the parentheses | |
RETURN SUBSTRING(@team, CHARINDEX('(', @team) + 1, CHARINDEX(')', @team) - CHARINDEX('(', @team) - 1) | |
END | |
ELSE | |
BEGIN | |
-- Return an error message if slot is not 0 or 1 | |
RETURN 'Invalid slot value. Please provide 0 or 1.' | |
END | |
END | |
-- Usage Example | |
-- @team = 'Chief Financial Office (CFO)' | |
-- @slot = 1 | |
-- EXEC GetTeamNameOrAbbreviation @team=@team @slot=@slot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment