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
 convert an int to a decimal value

Author  Topic 

turbohao
Starting Member

3 Posts

Posted - 2009-11-30 : 09:09:19
greetings
I try to convert an integer to a decimal value
COUNT(book_id) from books
i have a value 6,i want to have 6.00
i try to convert it with
CAST(count(book_id) as DECIMAL(1,2)) FROM books
does anyone know the correct syntax?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-30 : 09:15:41
1 count(book_id)*1.00
2 CAST(count(book_id) as DECIMAL(12,2))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-11-30 : 09:16:14
Hi

COUNT always returns an int data type value.

-------------------------
R...
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-30 : 09:31:10
To make it more clear:
6.00 would be DECIMAL(3,2)
1000.9 would be DECIMAL(5,1)
125.345 would be DECIMAL(6,3)

So DECIMAL(1,2) is not possible.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-30 : 09:34:52
yeah as DECIMAL (p,s) represents value with p precision (total number of digits p) and scale s (number of digits after decimal point s)
Go to Top of Page

turbohao
Starting Member

3 Posts

Posted - 2009-12-01 : 04:31:09
thanks for the explenation :)
Go to Top of Page
   

- Advertisement -