January 21, 2017 at 11:55 am
Comments posted to this topic are about the item right aligning
January 21, 2017 at 9:50 pm
The correct answer (out of the ones listed with the question) is actually pretty slow compared to other methods. Also, the correct answer takes inputs as FLOAT. That usually doesn't mean much but if you have more than 15 significant digits, you'll see truncation.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 22, 2017 at 1:54 am
Jeff Moden - Saturday, January 21, 2017 9:50 PMThe correct answer (out of the ones listed with the question) is actually pretty slow compared to other methods. Also, the correct answer takes inputs as FLOAT. That usually doesn't mean much but if you have more than 15 significant digits, you'll see truncation.
+100
😎
Even this
CONCAT(REPLICATE(CHAR(32),12 - LEN(T.mynum)),T.mynum)
is many times faster
January 22, 2017 at 10:28 pm
This was removed by the editor as SPAM
January 22, 2017 at 11:24 pm
Am I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00
and actually to my understanding all the options given is wrong. Please tell me.
:-PManie Verster
Developer
Johannesburg
South Africa
I can do all things through Christ who strengthens me. - Holy Bible
I am a man of fixed and unbending principles, the first of which is to be flexible at all times. - Everett Mckinley Dirkson (Well, I am trying. - Manie Verster)
January 23, 2017 at 2:59 am
Manie Verster - Sunday, January 22, 2017 11:24 PMAm I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00
and actually to my understanding all the options given is wrong. Please tell me.
I think that's down to using a non fixed width font
January 23, 2017 at 3:11 am
Manie Verster - Sunday, January 22, 2017 11:24 PMAm I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00
and actually to my understanding all the options given is wrong. Please tell me.
Send the results to Text
- Damian
January 23, 2017 at 5:35 am
Manie Verster - Sunday, January 22, 2017 11:24 PMAm I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00
and actually to my understanding all the options given is wrong. Please tell me.
I agree!
I guess since character data is right aligned in MY grid displace it is misleading, but the STR command did not align.
Oh, well.
January 23, 2017 at 6:18 am
Thanks for this question, Steve. Interesting is that str () takes input numeric data as a float data type.
In explanation it would probably be better to state that the STR () returns character data converted from numeric data.
January 23, 2017 at 6:34 am
djj - Monday, January 23, 2017 5:35 AMManie Verster - Sunday, January 22, 2017 11:24 PMAm I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00and actually to my understanding all the options given is wrong. Please tell me.
I agree!
I guess since character data is right aligned in MY grid displace it is misleading, but the STR command did not align.
Oh, well.
As previously stated, you need a fixed width font to get aligned results. Text results are usually configured to use a fixed width font, or you can change the one on the grid results.
January 23, 2017 at 7:08 am
I am surprised that nobody yet has stated that formatting belongs in the front end instead of directly from your query. 😉 Good question Steve!!!
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 23, 2017 at 4:03 pm
Sean Lange - Monday, January 23, 2017 7:08 AMI am surprised that nobody yet has stated that formatting belongs in the front end instead of directly from your query. 😉 Good question Steve!!!
I can't speak for anyone else but I never format for the front-end. That, notwithstanding, there are a whole lot of places that require such formatting that don't involve any front-end and every one of them is one of the dozens of columns in hundreds of "Fixed Field Format" files that I used to have to generate. I also don't use a front-end or Excel to generate my very nicely formatted "Morning Reports" for Overnight Job History, Enterprise Disk Report, or other reports. I do all of the HTML formatting using some really simple stuff in T-SQL because I'd rather not use SSIS, SSRS, or most of the other SQL Server 4 letter words. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
January 24, 2017 at 12:45 am
Luis Cazares - Monday, January 23, 2017 6:34 AMdjj - Monday, January 23, 2017 5:35 AMManie Verster - Sunday, January 22, 2017 11:24 PMAm I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00and actually to my understanding all the options given is wrong. Please tell me.
I agree!
I guess since character data is right aligned in MY grid displace it is misleading, but the STR command did not align.
Oh, well.
As previously stated, you need a fixed width font to get aligned results. Text results are usually configured to use a fixed width font, or you can change the one on the grid results.
Works fine when results are sent to text
January 24, 2017 at 3:04 am
BillLudlow - Tuesday, January 24, 2017 12:45 AMLuis Cazares - Monday, January 23, 2017 6:34 AMdjj - Monday, January 23, 2017 5:35 AMManie Verster - Sunday, January 22, 2017 11:24 PMAm I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00and actually to my understanding all the options given is wrong. Please tell me.
I agree!
I guess since character data is right aligned in MY grid displace it is misleading, but the STR command did not align.
Oh, well.As previously stated, you need a fixed width font to get aligned results. Text results are usually configured to use a fixed width font, or you can change the one on the grid results.
Works fine when results are sent to textTo be fair , the question stated right alignment and as demonstrated the answer doesn't achieve this. Relying on Font used isn't acceptable.
January 24, 2017 at 6:41 am
David Conn - Tuesday, January 24, 2017 3:04 AMBillLudlow - Tuesday, January 24, 2017 12:45 AMLuis Cazares - Monday, January 23, 2017 6:34 AMdjj - Monday, January 23, 2017 5:35 AMManie Verster - Sunday, January 22, 2017 11:24 PMAm I completely bonkers and am I the only one that read "right align"? I got this:
0.00
0.01
0.12
1.23
1.40
123.45
1234.56
12345.67
1.00
12.00
123.00
1234.00
12345.00
123456.00
1234567.00and actually to my understanding all the options given is wrong. Please tell me.
I agree!
I guess since character data is right aligned in MY grid displace it is misleading, but the STR command did not align.
Oh, well.As previously stated, you need a fixed width font to get aligned results. Text results are usually configured to use a fixed width font, or you can change the one on the grid results.
Works fine when results are sent to text
To be fair , the question stated right alignment and as demonstrated the answer doesn't achieve this. Relying on Font used isn't acceptable.
Relying on font is the only way to format strings without modifying settings from the front end. It's like saying ASCII art shouldn't rely on font.
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply