Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 value is not coming correctly

Author  Topic 

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-24 : 22:54:50
please help me in coorecting the program

declare @a as int,
@b as int,
@c as int,
@temp varchar(50)

set @a=100
set @b=230
set @c=(@a/@b)
set @temp = 'value of c='+CONVERT(varchar, @c)
print @temp --'value of c=',@c

( answer should be 100/230 = 0.434783)

but on execution the answer is:
value of c=0


tvspsekhar

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-25 : 00:25:34
[code]
declare @a as int,
@b as int,
@c as decimal(10,4),
@temp varchar(50)

set @a=100
set @b=230
set @c=(@a * 1.0/@b)
set @temp = 'value of c='+CONVERT(varchar(10), @c)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-25 : 11:47:32
see reason here

http://beyondrelational.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -