| Author |
Topic  |
|
|
jn-at-uk
Starting Member
20 Posts |
Posted - 04/29/2005 : 05:15:52
|
I have 2 values & want to return the decimal as a percentage declare @Sales decimal, @NoVisits int, @PerSales decimal select @Sales = 3 select @NoVisits = 1553
select @PerSales = (@Sales/@NoVisits * 100)
On my calculator I get a result of 0.1931745009. I want to display 0.19 % as my output. When I run this in sql, I get 0 result.
How do i get 0.19 % as my result
thanks |
|
|
nr
SQLTeam MVY
United Kingdom
12543 Posts |
Posted - 04/29/2005 : 05:16:41
|
select @PerSales = convert(decimal(18,2),(1.0*@Sales/@NoVisits * 100))
========================================== Cursors are useful if you don't know sql. DTS can be used in a similar way. Beer is not cold and it isn't fizzy. |
 |
|
|
jn-at-uk
Starting Member
20 Posts |
Posted - 04/29/2005 : 05:23:23
|
| thanku.....worked |
 |
|
|
tinhtam71
Starting Member
1 Posts |
Posted - 06/20/2007 : 13:35:39
|
I have the same problem, and tried your solution but it still showing 0. Is there any kind of sql setup involved? Thanks.
Tinhtam |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
Sweden
29138 Posts |
Posted - 06/20/2007 : 13:40:56
|
declare @sales int, @novisits int
select @Sales = 3, @NoVisits = 1553
select ltrim(str(100.0 * @Sales / @NoVisits, 6, 2))
Peter Larsson Helsingborg, Sweden |
 |
|
|
billsack
Starting Member
35 Posts |
Posted - 06/25/2007 : 08:54:38
|
Just do:
(Sales*100) / numberofvisits
Works ok for me... |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22460 Posts |
Posted - 06/25/2007 : 09:01:23
|
quote: Originally posted by tinhtam71
I have the same problem, and tried your solution but it still showing 0. Is there any kind of sql setup involved? Thanks.
Tinhtam
Post the code you used
Madhivanan
Failing to plan is Planning to fail |
 |
|
| |
Topic  |
|