You must Sign In to post a response.
  • Category: SQL Server

    Conversion varchar to int

    I have a table column varchar type, values are such 1,2.5,6.7,1.7,2.8,1.0 etc..
    I want to update this round the number which are having with ".".
    1.0 should be updated as 1 and 6.7 should be updated as 7 (this column is varchar data type)
  • #769557
    Hi Sankar,

    You can cast your values to float and then to int.See the example below:

    declare @x varchar(10)='96.907'

    select cast(cast(@x as float) as int) IntValue

    Anjali Bansal

    ~Give your best and lead the world

  • #769560

    you can use this piece of query working Good then future Query or issue post again

    declare @d nvarchar(20)='1.0'
    select ROUND(@d,2)
    --your output

    declare @j nvarchar(20)='6.7'
    select ROUND(@j,0)

    --your output

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #769722
    Write stored proc with loop and read all the table values and apply below logic before updating values into table

    declare @column1 nvarchar(max)
    select @column1 = '6.7'
    declare @res decimal(2,0)
    SELECT @res=round(CAST(@column1 AS decimal(2,0)),0)
    select @res

    B.Ramana Reddy

  • Sign In to post your comments