Solved

putting commas in numeric value for dollars

Posted on 2016-07-28
11
64 Views
Last Modified: 2016-07-29
I have a field i'm creating

cast (sum(tas.R12Value) as decimal (8,0)) as r12value

which is rounding the number for me fine.
1430022 however
I'm missing the commas ?
would like to see.
1,430,022

Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 6
  • 4
11 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41733803
>cast (sum(tas.R12Value) as decimal (8,0)) as r12value
>I'm missing the commas ?
That's because numeric data types such as int, decimal, numeric, etc. only store the number and not any cosmetic formatting such as currency symbols and thousands-separating commas.

Do your formatting in the presentiation (i.e. reporting) layer, not in the data layer.

So ... explain for us where you would 'like to see' the commas.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 41733816
expressed in dollar amounts
12,000
1,000
13,248,765


etc...
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41733818
That wasn't my question.  Where would you like to see these commas?  In the database, on a report, in an ETL feed, on a boat, with a goat, ...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Author Comment

by:fordraiders
ID: 41733827
dr suess...lol  

on asp.net c#  gridview
0
 
LVL 3

Author Comment

by:fordraiders
ID: 41733830
this is what I have thus far.

e.Row.Cells[3].Text = String.Format("$ {0:C}", e.Row.Cells[3].Text);
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 100 total points
ID: 41733835
Ok.  In that case I recommend doing this in the formatting of the gridview.  Since I'm not an expert in either, I'll add those two zones to this question and step back so those experts can read your question and respond.
0
 
LVL 40

Accepted Solution

by:
Sharath earned 400 total points
ID: 41733867
May be this.
convert(varchar,convert(money,sum(tas.R12Value)),1) AS r12value

Open in new window

0
 
LVL 3

Author Comment

by:fordraiders
ID: 41733873
sharath, perfect,...

Thanks !!
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 41733882
Thanks Sharath and
Jimbo, Thanx for the direction and help !!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41733887
Thanks for the split, but I'm going to recommend against the approach sharath posted.   If you convert these numbers to varchar in your data layer, then they will be varchar's in the reporting layer, which means the only way it will be able to participate in math such as addition, subtraction, subtotals, etc. is by implicit conversion, and the characters may (will?) cause it to throw an error.

Better to format in the report.
1
 
LVL 3

Author Comment

by:fordraiders
ID: 41734913
Jmbo, i tend to agree. Luckily this is just a one time view.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql 2014,  lock limit 5 32
SQL view 2 27
SQL Syntax: How to force case sensitive query? 2 26
MSSQL Import .SQL files - Increase Import Speed 9 35
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question