HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Remove Dot at end of line of the string in SQLserver

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thelinesqlserverdotremoveendstring

Problem

I would to like to remove the dot at end of the line alone if exists in the string in SQL server.

Example:

ABC Private's co., ltd.


Required output:

ABC Private's co., ltd

Solution

You can use like to check for a . at the end of the string.

declare @S nvarchar(max) = 'ABC Private''s co., ltd.';

select case when @S like '%.' 
         then left(@S, len(@S) - 1) 
         else @S 
       end;

Code Snippets

declare @S nvarchar(max) = 'ABC Private''s co., ltd.';

select case when @S like '%.' 
         then left(@S, len(@S) - 1) 
         else @S 
       end;

Context

StackExchange Database Administrators Q#185571, answer score: 6

Revisions (0)

No revisions yet.