SQL Stored Procedure Division rounding with decimals -


i have created simple stored procedure division. when run it, rounds numbers though decimals. instance, 5.0/10.0=1. why this?

here script:

go create procedure uspdivide2numbers2      @intvalue1 decimal     ,@intvalue2 decimal set nocount on      --report errors  declare @intresult decimal = 0  --do calculation select @intresult = @intvalue1 / @intvalue2  --display results select @intresult intresult  go  uspdivide2numbers2 5.0, 10.0 

thank you

you have not defined scale decimal datatype.

declare stored procedure parameters scale specified.

  @intvalue1 decimal(10,2)     ,@intvalue2 decimal(10,2) 

and

declare @intresult decimal(10,2) 

this means @intresult can have 2 digits after decimal point (i.e. scale =2 ) , maximum 10 digits. if don't define scale , sql assumes scale =0 , hence won't digits after decimal point.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -