How to convert integer to decimal in SQL Server query?

后端 未结 5 1743
孤独总比滥情好
孤独总比滥情好 2020-12-30 18:56

A column height is integer type in my SQL Server table. I want to do a division and have the result as decimal in my query:

Select (height/10) a         


        
5条回答
  •  一整个雨季
    2020-12-30 19:02

    You can either cast Height as a decimal:

    select cast(@height as decimal(10, 5))/10 as heightdecimal
    

    or you place a decimal point in your value you are dividing by:

    declare @height int
    set @height = 1023
    
    select @height/10.0 as heightdecimal
    

    see sqlfiddle with an example

提交回复
热议问题