Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
@Cte1_count='2'
@cte2_count='500'

i want Totalcount=0.42% format only

even i tried like
(Cte1_count/cte2_count)*100

but its show 0 only please help me
Posted

Convert one for count into floating point numeric value

SQL
declare @Cte1_count INT = 2
declare @Cte2_count INT = 500

select (@Cte1_count/CONVERT(FLOAT, @Cte2_count))*100

result 

----------------------
0.4

(1 row(s) affected)
 
Share this answer
 
Comments
Member 10562086 12-Feb-14 1:09am    
no sir its not working
prakashdotnet 12-Feb-14 1:54am    
It's working please try same query in SSMS.
prakashdotnet 12-Feb-14 1:55am    
or post your query.
Member 10562086 12-Feb-14 23:53pm    
<pre lang="sql">cte3_persenta (per) as
(select ((cte1.totalcount/cte2.TotaCount)* 100 )
from cte1,cte2)</pre>

i am creating one new cte table shown above
from that value '2'coming from cte1.totalcount and
value '500' coming from cte2.TotaCount
i want percentage of those value it should be in 0.00% format


i want ans of per from cte3 table is =0.40%

please help me sir
prakashdotnet 13-Feb-14 0:20am    
declare @Cte1_count INT = 2
declare @Cte2_count INT = 500

select CONVERT(VARCHAR, CONVERT(NUMERIC(16,2),(@Cte1_count/CONVERT(FLOAT, @Cte2_count))*100))+ '%' AS 'cte3_persent(per)'

Result
cte3_persent(per)
-------------------------------
0.40%

(1 row(s) affected)
Try this way

SQL
declare @Cte1_count int = 2
declare @cte2_count int = 500
declare @dec decimal (6,2)
SET @dec = (CAST(@Cte1_count AS Float)/CAST(@cte2_count AS FLoat))*100
print @dec
 
Share this answer
 
Comments
Member 10562086 12-Feb-14 1:09am    
no sir its not working
Sandeep Singh Shekhawat 12-Feb-14 1:14am    
It's working. What are you getting and what is your need? Try this

declare @Cte1_count int = 2
declare @cte2_count int = 500
declare @dec decimal (6,2)
SET @dec = (CAST(@Cte1_count AS Float)/CAST(@cte2_count AS FLoat))*100
print CAST(@dec AS nvarchar(10))+'%'
Member 10562086 12-Feb-14 23:55pm    
cte3_persent (per) as
(select ((cte1.totalcount/cte2.TotaCount)* 100 )
from cte1,cte2)

i am creating one new cte table shown above
from that value '2'coming from cte1.totalcount and
value '500' coming from cte2.TotaCount
i want percentage of those value it should be in 0.00% format


i want ans of per from cte3 table is =0.40%

please help me sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900