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)
 Percentage

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2013-11-20 : 11:22:31
Hi All,
I am running below query in

Update T1
set Per=round(100*cast(cast(Total_Sale as Decimal(16,4))/Total_Calls as decimal(16,4)),2)

Now it is updating data like this 73.50,10
I want all the places 2 decimal so output should be 73.50,10.00
please suggest

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-11-20 : 12:18:23
From what I can tell, the right hand side of your update statement yields a decimal(16,4), rounded to do decimal places. For example, 73.5000, 10.0000.

What is the data type of the Per column?
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2013-11-20 : 12:23:20
Float
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2013-11-20 : 12:23:21
Float
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-11-20 : 12:51:58
FLOAT data type does not store the data with a certain number of trailing zeros. If you want to get the data with a trailing decimals, when you select the data from the table, cast it to decimal with a scale of 2. For example:
SELECT CAST(Per AS DECIMAL(19,2)) FROM T1
Go to Top of Page
   

- Advertisement -