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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Decimal-Problem

Author  Topic 

brandointheweb
Starting Member

2 Posts

Posted - 2008-06-19 : 03:21:15
Hi to all,
I'm trying to get a decimal value like 0.75 for later calculating the percentage.
But all the time my result is 1. I slowly get frustrated!
Can someone give me a hint?
My Code:

DECLARE @sales decimal ,@sales_dec decimal
select @sales = 75
select @sales_dec= CONVERT(DECIMAL(18,2),@sales/100)

This code runs in an update trigger which inserts the @sales_dec-value in another decimal(18,2)-column, but only a "1"!
Thanks

raky
Aged Yak Warrior

767 Posts

Posted - 2008-06-19 : 03:32:50
quote:
Originally posted by brandointheweb

Hi to all,
I'm trying to get a decimal value like 0.75 for later calculating the percentage.
But all the time my result is 1. I slowly get frustrated!
Can someone give me a hint?
My Code:

DECLARE @sales decimal ,@sales_dec decimal
select @sales = 75
select @sales_dec= CONVERT(DECIMAL(18,2),@sales/100)

This code runs in an update trigger which inserts the @sales_dec-value in another decimal(18,2)-column, but only a "1"!
Thanks



Try this

DECLARE @sales decimal ,@sales_dec decimal
select @sales = 75
select @sales_dec= CONVERT(DECIMAL(18,2),@sales*1.0/100)

select @sales_dec
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2008-06-19 : 03:51:57
[code]
DECLARE @sales decimal ,@sales_dec decimal(10,2)
select @sales = 75
select @sales_dec= @sales/100.0
Select @sales_dec
[/code]

Chirag

http://www.chirikworld.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-19 : 04:35:12
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx
Go to Top of Page

brandointheweb
Starting Member

2 Posts

Posted - 2008-06-19 : 09:43:01
Thanks, that worked!
Go to Top of Page
   

- Advertisement -