Skip to content

Instantly share code, notes, and snippets.

@adgedenkers
Created November 15, 2023 12:12
Show Gist options
  • Save adgedenkers/c8c778f32f38e0b9cd9275487a240016 to your computer and use it in GitHub Desktop.
Save adgedenkers/c8c778f32f38e0b9cd9275487a240016 to your computer and use it in GitHub Desktop.
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