Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Thousand Seperator Magic
Thousand Seperator Magic
Rate Topic
Display Mode
Topic Options
Author
Message
karthik M
karthik M
Posted Saturday, December 01, 2012 8:33 PM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 6:32 AM
Points: 2,006,
Visits: 2,458
All,
I have recently faced the below scenario.
i.e to add comma as the thousand seperator
I have searched here and found the below query
select convert(varchar,cast(12345678918 as money),1)
how this query is adding ',' ?
even i tried different combination of numbers which start with 1, all of them adding ',' . But when i use other than 1, it didn't. how? what is the magic behind this '1' ?
karthik
Post #1391688
Lynn Pettis
Lynn Pettis
Posted Saturday, December 01, 2012 9:01 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 6:14 PM
Points: 21,588,
Visits: 27,379
karthik M (12/1/2012)
All,
I have recently faced the below scenario.
i.e to add comma as the thousand seperator
I have searched here and found the below query
select convert(varchar,cast(12345678918 as money),1)
how this query is adding ',' ?
even i tried different combination of numbers which start with 1, all of them adding ',' . But when i use other than 1, it didn't. how? what is the magic behind this '1' ?
From Books Online, CONVERT function:
money and smallmoney Styles
When expression is money or smallmoney, style can be one of the values shown in the following table. Other values are processed as 0.
Value Output
0 (default)
No commas every three digits to the left of the decimal point, and two digits to the right of the decimal point; for example, 4235.98.
1
Commas every three digits to the left of the decimal point, and two digits to the right of the decimal point; for example, 3,510.92.
2
No commas every three digits to the left of the decimal point, and four digits to the right of the decimal point; for example, 4235.9819.
126
Equivalent to style 2 when converting to char(n) or varchar(n)
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1391690
CELKO
CELKO
Posted Saturday, December 01, 2012 9:01 PM
SSCommitted
Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945,
Visits: 2,782
to add comma as the thousand separator
NO! Display formatting is done in the presentation layers of any tiered architecture. The proprietary MONEY data type is left-over from the 1970's Sybase dialect. It formats numeric values to look like they had been written with a COBOL PICTURE clause.
01 FOOBAR PICTURE $999,999,999,999V9999
We do not do this in SQL any more.
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1391691
Lynn Pettis
Lynn Pettis
Posted Saturday, December 01, 2012 9:16 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 6:14 PM
Points: 21,588,
Visits: 27,379
CELKO (12/1/2012)
to add comma as the thousand separator
NO! Display formatting is done in the presentation layers of any tiered architecture. The proprietary MONEY data type is left-over from the 1970's Sybase dialect. It formats numeric values to look like they had been written with a COBOL PICTURE clause.
01 FOOBAR PICTURE $999,999,999,999V9999
We do not do this in SQL any more.
Joe, you're a dinosaur like me. Most people on this forum probably don't even know what COBOL is.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1391695
CapnHector
CapnHector
Posted Monday, December 03, 2012 2:29 PM
SSC Eights!
Group: General Forum Members
Last Login: Yesterday @ 10:07 AM
Points: 935,
Visits: 1,709
Lynn Pettis (12/1/2012)
CELKO (12/1/2012)
to add comma as the thousand separator
NO! Display formatting is done in the presentation layers of any tiered architecture. The proprietary MONEY data type is left-over from the 1970's Sybase dialect. It formats numeric values to look like they had been written with a COBOL PICTURE clause.
01 FOOBAR PICTURE $999,999,999,999V9999
We do not do this in SQL any more.
Joe, you're a dinosaur like me. Most people on this forum probably don't even know what COBOL is.
Isn't that a shade of blue
as far as why to do it, there are some limited times when i want my results window to look preaty on a couple of queries i run when checking our platform. I would prefer to leave it to the UI but when the UI does not have the options (SSMS) in the SQL is the only place to really do it.
For faster help in answering any problems Please read
How to post data/code on a forum to get the best help - Jeff Moden
for the best way to ask your question.
For performance Issues see how we like them posted here:
How to Post Performance Problems - Gail Shaw
Need to Split some strings?
Jeff Moden's DelimitedSplit8K
Jeff Moden's
Cross tab and Pivots Part 1
Jeff Moden's
Cross tab and Pivots Part 2
Jeremy Oursler
Post #1392149
CELKO
CELKO
Posted Monday, December 03, 2012 3:56 PM
SSCommitted
Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945,
Visits: 2,782
Joe, you're a dinosaur like me. Most people on this forum probably don't even know what COBOL is.
And most of them have never see a punch card or used a mag tape drive. But they keep re-inventing them in SQL.
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1392174
Lynn Pettis
Lynn Pettis
Posted Monday, December 03, 2012 6:06 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 6:14 PM
Points: 21,588,
Visits: 27,379
CELKO (12/3/2012)
Joe, you're a dinosaur like me. Most people on this forum probably don't even know what COBOL is.
And most of them have never see a punch card or used a mag tape drive. But they keep re-inventing them in SQL.
And that's part of the problem, they have no idea what you are even talking about.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1392205
dogramone
dogramone
Posted Monday, December 03, 2012 8:38 PM
Mr or Mrs. 500
Group: General Forum Members
Last Login: Sunday, May 05, 2013 9:00 PM
Points: 510,
Visits: 2,085
And unfortunately none of them are intelligent enough to investigate. Oh for the good old days when IT was a black box that no one got involved in unless they were truly inspired. Now it's become jut like accounting, a degree and job only and in it jut for the money.
Joe please keep hitting them with a hammer, eventually it might imprint somewhere.
Post #1392232
Evil Kraig F
Evil Kraig F
Posted Monday, December 03, 2012 8:45 PM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 6:03 PM
Points: 5,658,
Visits: 6,099
dogramone (12/3/2012)
And unfortunately none of them are intelligent enough to investigate. Oh for the good old days when IT was a black box that no one got involved in unless they were truly inspired. Now it's become jut like accounting, a degree and job only and in it jut for the money.
Joe please keep hitting them with a hammer, eventually it might imprint somewhere.
Oh, don't worry, he definately makes an impression.
You bring up a good point though. Eventually (we're getting there) the tools become good enough that the average person can roll their own for small projects. They may not be a professional cabinet maker but the average person just needs to be able to slap their IKEA bookshelf together. Quality will always be required at some level, but every contacts database out there really doesn't (usually) need top-end computer science knowledge. However, I'm helping to horribly derail this poor thread, and probably shouldn't soapbox that topic here. Though, I do have a new blog post idea.
- Craig Farrell
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions
|
Forum Netiquette
For index/tuning help, follow these directions.
|
Tally Tables
Twitter: @AnyWayDBA
Post #1392233
Lynn Pettis
Lynn Pettis
Posted Monday, December 03, 2012 8:58 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 6:14 PM
Points: 21,588,
Visits: 27,379
dogramone (12/3/2012)
And unfortunately none of them are intelligent enough to investigate. Oh for the good old days when IT was a black box that no one got involved in unless they were truly inspired. Now it's become jut like accounting, a degree and job only and in it jut for the money.
Joe please keep hitting them with a hammer, eventually it might imprint somewhere.
I'm sorry, but Mr. Celko insults the intelligence of others enough, we don't need someone else following in his unprofessional foot steps.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1392235
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.