-1

For input

A.B.1.23

I want output

A.B.1

TTT
  • 1,848
  • 2
  • 30
  • 60

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,242,037
  • 58
  • 646
  • 786
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,991
  • 10
  • 12
0

You can use this also :

DECLARE @ AS VARCHAR(100) = 'A.B.1.23'
select substring(@, 1, len(@) - charindex('.', reverse(@)))
Md. Suman Kabir
  • 5,243
  • 5
  • 25
  • 43