January 10, 2017 at 8:59 pm
How do you display data in thousands with 1 decimal?
10,500 ==> 10.5
January 10, 2017 at 9:21 pm
SELECT
CONVERT(DECIMAL(18,1), 10.500), -- output as a decimal
LTRIM(STR(10.500, 18,1)) -- output as a string
_____________
Code for TallyGenerator
January 11, 2017 at 5:40 am
You could also use
SELECT FORMAT(10.500,'N1')
See documentation for the FORMAT function.
Thomas Rushton
blog: https://thelonedba.wordpress.com
January 11, 2017 at 5:45 am
ThomasRushton (1/11/2017)
You could also use
SELECT FORMAT(10.500,'N1')
Although FORMAT is extremely slow compared to CONVERT.
https://sqlperformance.com/2015/06/t-sql-queries/format-is-nice-and-all-but
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 11, 2017 at 5:59 am
GilaMonster (1/11/2017)
ThomasRushton (1/11/2017)
You could also use
SELECT FORMAT(10.500,'N1')
Although FORMAT is extremely slow compared to CONVERT.
https://sqlperformance.com/2015/06/t-sql-queries/format-is-nice-and-all-but
Good point.
Mind you, this sort of formatting should be done away from the database layer anyway... 😉
Thomas Rushton
blog: https://thelonedba.wordpress.com
January 11, 2017 at 6:46 am
ThomasRushton (1/11/2017)
GilaMonster (1/11/2017)
ThomasRushton (1/11/2017)
You could also use
SELECT FORMAT(10.500,'N1')
Although FORMAT is extremely slow compared to CONVERT.
https://sqlperformance.com/2015/06/t-sql-queries/format-is-nice-and-all-but
Good point.
Mind you, this sort of formatting should be done away from the database layer anyway... 😉
What about cast vs format?
January 11, 2017 at 11:15 am
ThomasRushton (1/11/2017)
GilaMonster (1/11/2017)
ThomasRushton (1/11/2017)
You could also use
SELECT FORMAT(10.500,'N1')
Although FORMAT is extremely slow compared to CONVERT.
https://sqlperformance.com/2015/06/t-sql-queries/format-is-nice-and-all-but
Good point.
Mind you, this sort of formatting should be done away from the database layer anyway... 😉
Only if there is another layer. I do a lot of formatting (never saved in a permanent table, to be sure) for reports generated by SQL Server that have nothing to do with things like SSRS or other reporting tools because they have to be saved to a file with particular requirements.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 11, 2017 at 11:16 am
Manic Star (1/11/2017)
ThomasRushton (1/11/2017)
GilaMonster (1/11/2017)
ThomasRushton (1/11/2017)
You could also use
SELECT FORMAT(10.500,'N1')
Although FORMAT is extremely slow compared to CONVERT.
https://sqlperformance.com/2015/06/t-sql-queries/format-is-nice-and-all-but
Good point.
Mind you, this sort of formatting should be done away from the database layer anyway... 😉
What about cast vs format?
The testing that I've done on format shows that FORMAT is generally 44 times slower than either CAST or CONVERT. Since it's based on .net functionality as a CLR, it makes you wonder how it performs for managed code.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply