decimal point

  • Hi,

    I have codes like this:

    E955.0

    E955.1

    E955.2

    I want to select these codes without the decimal points like(without rounding up):

    E9550

    E9551

    E9552

    How can i do this?

    Thanks

  • If the pattern is consistent, meaning there is only one instance of the "." in the string, you could use something like this.

    DECLARE @String NVARCHAR(50)

    SET @String = 'E955.0'

    SELECT SUBSTRING(@String,0,CHARINDEX('.',@String))

    Hope this helps.

    "Any fool can write code that a computer can understand. Good programmers write
    code that humans can understand." -Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999

  • Or this:

    SELECT REPLACE(@String, '.', '')

    John

  • Use charindex/patindex to find the decimal point, then subsctring to remove it. Concatenate the before decimal point with the after.

  • My bad. I did not see that the number needed to be appended. John's suggestion works great. I thought you only needed what was left of the ".". Sorry for the confusion. Need more coffee. 😀

    "Any fool can write code that a computer can understand. Good programmers write
    code that humans can understand." -Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply