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.
| Author |
Topic |
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-07-01 : 12:03:55
|
| HiIn one of my select fields in a query I have the following:CAST(dbo.FunctionA 'Param1') AS FLOAT)/CAST((dbo.FunctionB, 'ParamB') AS FLOAT) AS AliasMy returned value is like this:1.23233424333But I want to have it only with 2 decimal places but am unsure what to use e.g. Cast whole result to decimal or what and can't really find a suitable example that reflects my problem.Could anyone suggest what it is I should do, I know there are probably 2 or 3 options I could use.G |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-07-01 : 12:09:57
|
| There a several methods, the most common seem to be CASTing as DECIMAL/NUMERIC or using the ROUND function. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-07-01 : 12:27:36
|
| CONVERT(varchar(20), MyMoneyDatatype, 1)will do it ... got to be able to CAST the value as MONEY thoughShould really do the "presentation" stuff in the front end though. |
 |
|
|
Grifter
Constraint Violating Yak Guru
274 Posts |
Posted - 2010-07-02 : 05:55:09
|
quote: WHY are you using FLOAT?Brett
One of the functions returns an INT and the other returns float. I suppose now I should only be casting one to float but i think originally it was to make sure I was dividing two of the same data types. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-02 : 08:41:40
|
round(your_value_or_expression,2,1) as YourName will cut the value to 2 decimals instead of rounding the value. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|