Function to Clear Trailing in a Post in SQL Server
Hello everyone,
In this article, I will provide information about the function that clears the trailing part in an article in SQL Server.
In SQL Server, in some cases, we may want to clear the trailing part of an article.
You can easily do this with the help of the function below.
CREATE FUNCTION ClearTrailingPart
(
@Text NVARCHAR(200),
@Character CHAR(1)
)
RETURNS NVARCHAR(200)
AS
BEGIN
DECLARE @Result NVARCHAR(200) = SUBSTRING(@Text, 0, CHARINDEX(@Character, @Text));
RETURN @Result;
END;
--Use of the function
SELECT dbo.ClearTrailingPart('yavuz.23', '.');
SELECT dbo.ClearTrailingPart('yavuz-23666', '-');
SELECT dbo.ClearTrailingPart('yavuz-2', '-');
When you run the code, you will get a result like the one below.
As you can see, the last part has been cleared.
Good luck to everyone in business and life.