Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how can we fix $ sign in before multiplication value in sql. Means i have two column

hour(10), rate(10) now i want a sql query through which i get $Hour*rate ($100)
Posted

Depends. If your Hour and Rate columns are text based, than the first thing you want to do is to replace them with number values. It make sit a lot, lot easier to do math, because you don't have to convert them to numbers each time you use them, with the inherent error checking that that involves. So assuming you have gone for numeric fields:
SQL
SELECT '$' + CONVERT(VARCHAR(10), Hour * Rate) FROM MyTable
 
Share this answer
 
Comments
Mas11 27-Jun-12 3:36am    
Ok, Thanks a lot Griff, but this query show result in this way ($112.123) & i want decimal up to 2 digit ie. $112.12. How can we add decimal up to 2 digit in this query. i write this but it doesn't work. Kindly help me where i does mistake.

SELECT '$' + CONVERT(CAST(ROUND(expenses.hours*expenses.rate , 2) as DECIMAL(18,2))) as Total
Mas11 27-Jun-12 3:45am    
Thanks a lot for your responce. I have solved this.

select '$' + CONVERT(VARCHAR(10), CAST(ROUND(expenses.hours*expenses.rate , 2) as DECIMAL(18,2))) as Total
OriginalGriff 27-Jun-12 3:54am    
Well done!
select '$' + CONVERT(VARCHAR(10), CAST(ROUND(expenses.hours*expenses.rate , 2) as DECIMAL(18,2))) as Total
 
Share this answer
 
v2

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