Remove Decimals using PATINDEX

Rajnilari2015
Posted by Rajnilari2015 under Sql Server category on | Points: 40 | Views : 148
DECLARE @somevalue VARCHAR(50) = '123459078.9005'; --set the initial value

DECLARE @nonZeroPosition INT -- variable to store the occurance of first non zero value position

SELECT @nonZeroPosition = PATINDEX('%[[.]%',@somevalue) --Ensures the occurance of a decimal

SELECT ValueBeforeDecimal = LEFT(@somevalue,@nonZeroPosition-1)


ValueBeforeDecimal
----------------------
123459078

Comments or Responses

Login to post response