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.

Function to Clear Trailing in a Post in SQL Server

As you can see, the last part has been cleared.

Good luck to everyone in business and life.

152 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!