- Moderator
- #1
SO I have this table... and I've been told the rule is:
"If the number is < 10, then it should be 3 decimal places. If the number is > 10, then it should be 0 decimal places."
In other words:
0.110 ----> 0.110
1.1 ----> 1.100
9.99 ----> 9.990
10.123 ----> 10
150.5 ----> 150
... and so forth.
So meanwhile, the "Result" field is a nvarchar (meaning that it is a string).... and because of some other calculations going on, there is a "CASE" statement in there as well.... here's a snippet....
So as you can see, there is some math going on there already, but I need to additionally process and say "If it's <10, then format it as #0.000 otherwise format it as ##0" sort of thing.
Any thoughts on an easy way to accomplish this? If I were writing it in VB, I'd just write a quick function to convert the string to a number, see if it's > 10, if so than INT the number, otherwise format it #.000.....
TIA!
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg
"If the number is < 10, then it should be 3 decimal places. If the number is > 10, then it should be 0 decimal places."
In other words:
0.110 ----> 0.110
1.1 ----> 1.100
9.99 ----> 9.990
10.123 ----> 10
150.5 ----> 150
... and so forth.
So meanwhile, the "Result" field is a nvarchar (meaning that it is a string).... and because of some other calculations going on, there is a "CASE" statement in there as well.... here's a snippet....
Code:
... previous part of select statement ....
CASE WebSample.Units
WHEN 'mg/Kg' THEN [Sign] + Result
WHEN 'ug/KG' THEN [Sign] + CAST(CONVERT(decimal(18,0),Result)*.001 AS nvarchar)
WHEN '%' THEN [Sign] + Result + '%'
WHEN '' THEN 'N/A'
ELSE [Sign] + Result
END AS Result,
.... continued part of select, including PIVOT ....
So as you can see, there is some math going on there already, but I need to additionally process and say "If it's <10, then format it as #0.000 otherwise format it as ##0" sort of thing.
Any thoughts on an easy way to accomplish this? If I were writing it in VB, I'd just write a quick function to convert the string to a number, see if it's > 10, if so than INT the number, otherwise format it #.000.....
TIA!
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg