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

    Conversion varchar to int

    Hi,
    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

    Thanks!
    Anjali Bansal

    ~Give your best and lead the world

  • #769560
    Hi

    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
    --1

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

    --your output
    --7


    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

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


  • Sign In to post your comments