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 2000 Forums
 Transact-SQL (2000)
 a problem with the decimal data type

Author  Topic 

tegryan
Starting Member

22 Posts

Posted - 2002-06-26 : 06:15:58
I am using win 2k, SQL server 2k with SP2. This question is best shown by the code.

When I execute this:

declare @tickets decimal(15,5)
set @tickets = 2025/2000
Print @tickets

I get:

1.00000


but when I execute this:

declare @tickets decimal(15,5)
set @tickets = 2025.0/2000
Print @tickets

I get the right anwser:

1.01250

It seems that the number is being formated like a decimal, but calculated like an integer. How can I get around this? All the numbers coming in are integers, but I need to know the decimal value to perform a ceiling function on it.

nivaskhan
Starting Member

17 Posts

Posted - 2002-06-26 : 06:31:26
use this

declare @tickets decimal(15,5)
set @tickets = CONVERT(DECIMAL,2025)/2000
Print @tickets

since the numbers involved in the division is both integer types,
the result is of integer type which is store in deimal variable @tickets

So by changing any one number involved in the division
to DECIMAL or FLOAT will give you the required result.


Regards,
Nivas
Go to Top of Page
   

- Advertisement -