-1

For input

A.B.1.23

I want output

A.B.1

TTT
  • 1,710
  • 1
  • 25
  • 54

3 Answers3

1

In SQL Server, you can use:

select left(col, len(col) - charindex('.', reverse(col)))

This is dynamic and simply assumes that there is at least on '.' in the column.

Gordon Linoff
  • 1,122,135
  • 50
  • 484
  • 624
1

See if this helps..

DECLARE @ AS VARCHAR(100) = 'A.B.1.23'
SELECT REVERSE(SUBSTRING(REVERSE(@),CHARINDEX('.',REVERSE(@),0)+1,LEN(REVERSE(@))))
Pawan Kumar
  • 1,949
  • 8
  • 10
0

You can use this also :

DECLARE @ AS VARCHAR(100) = 'A.B.1.23'
select substring(@, 1, len(@) - charindex('.', reverse(@)))
Md. Suman Kabir
  • 4,057
  • 3
  • 20
  • 37