Jun 3, 2002 #1 DavidJA Programmer Jan 10, 2002 58 AU Hey all, consider the following code: create table #test (Num decimal(6,2)) insert #test (num) select 50 / 100 select * from #test For me this returns 0.00, but 50/100 = .05 how can I make this code return 0.05.
Hey all, consider the following code: create table #test (Num decimal(6,2)) insert #test (num) select 50 / 100 select * from #test For me this returns 0.00, but 50/100 = .05 how can I make this code return 0.05.
Jun 3, 2002 #2 crystalized Programmer Jul 10, 2000 390 CA could you try declaring variables of type number or decimal, set them to 50 and 100 then divide using the variables. I don't know if this will help but it is worth a shot. Crystal crystalized_s@yahoo.com -------------------------------------------------- Experience is one thing you can't get for nothing. -Oscar Wilde Upvote 0 Downvote
could you try declaring variables of type number or decimal, set them to 50 and 100 then divide using the variables. I don't know if this will help but it is worth a shot. Crystal crystalized_s@yahoo.com -------------------------------------------------- Experience is one thing you can't get for nothing. -Oscar Wilde
Jun 3, 2002 #3 cmmrfrds Programmer Feb 13, 2000 4,690 US The numbers are integer so there will be no decimal. create table #test (Num decimal(6,2)) insert #test (num) select convert (decimal(6,2),50) / convert (decimal(6,2),100) select * from #test Upvote 0 Downvote
The numbers are integer so there will be no decimal. create table #test (Num decimal(6,2)) insert #test (num) select convert (decimal(6,2),50) / convert (decimal(6,2),100) select * from #test
Jun 3, 2002 #4 pankajv Programmer Jan 30, 2002 178 IN Converting one of them to a decimal number will also do the trick Upvote 0 Downvote
Jun 5, 2002 #5 crystalized Programmer Jul 10, 2000 390 CA This also works declare @temp1 decimal(6,2), @temp2 decimal(6,2) set @temp1=50 set @temp2=100 create table #test (Num decimal(6,2)) insert #test (num) select @temp1 / @temp2 select * from #test Although is admittedly a little more verbose than the other solution. Crystal crystalized_s@yahoo.com -------------------------------------------------- Experience is one thing you can't get for nothing. -Oscar Wilde Upvote 0 Downvote
This also works declare @temp1 decimal(6,2), @temp2 decimal(6,2) set @temp1=50 set @temp2=100 create table #test (Num decimal(6,2)) insert #test (num) select @temp1 / @temp2 select * from #test Although is admittedly a little more verbose than the other solution. Crystal crystalized_s@yahoo.com -------------------------------------------------- Experience is one thing you can't get for nothing. -Oscar Wilde