SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Currency Format


Currency Format

Author
Message
YumiPhx
YumiPhx
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 78
Hi all,
Do you know how to cut off the decimal for the Currency format without ROUNDING up the number?

example: $4,816,220.65

I want the number show on report: $4,816,220 NOT $4,816,221

your help is much appreciated,

Yumi
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)

Group: General Forum Members
Points: 84677 Visits: 41069
YumiPhx (9/4/2009)
Hi all,
Do you know how to cut off the decimal for the Currency format without ROUNDING up the number?

example: $4,816,220.65

I want the number show on report: $4,816,220 NOT $4,816,221

your help is much appreciated,

Yumi



First of all, you should never store formatted data in the database and you usually shouldn't format data in SQL Server. It's much better for a dozen reasons to do the formatting in the GUI.

Also, without knowing the underlying datatype of the data you want to convert, I can only guess that you have the data stored as VARCHAR (again, that's a VERY bad thing to do). Here's how to preserve the formatting you requested on a VARCHAR...

--===== Create a data sample... this is not a part of the solution
DECLARE @SomeFormattedColumn VARCHAR(20)
SET @SomeFormattedColumn = '$4,816,220.65'

--===== Solve the problem
SELECT LEFT(@SomeFormattedColumn, LEN(@SomeFormattedColumn)-3)



Of course, that will work correctly ONLY if all your data has a decimal point and two decimal places. You could use this as a bit of a guarantee...

--===== Create a data sample... this is not a part of the solution
DECLARE @SomeFormattedColumn VARCHAR(20)
SET @SomeFormattedColumn = '$4,816,220.65'

--===== Solve the problem
SELECT LEFT(@SomeFormattedColumn,
LEN(@SomeFormattedColumn)
- ISNULL(LEN(@SomeFormattedColumn)
- NULLIF(CHARINDEX('.',@SomeFormattedColumn),0)+1
,0)
)



The numeric functions in that will be faster than doing multiple CONVERTs or CASTS or even using REVERSE.

... and now you see why you shouldn't store or create formatted data in SQL Server. ;-)

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
YumiPhx
YumiPhx
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 78
Hi Jeff,
Thank you so much for your reply.
The fields that selected for the report are from SQL server BD,
define as (Float, null). When I set the Currency format in RS as C
it give me 2 decimals. If I set C0, it will remove the decimal but round it up automatically.
I tried to use your suggestion but somehow I am having problem with Charindex for those number greater than 7 digits...No clue why.

Finally, I used FLOOR function and it works fine.

Select Floor(floatNumberColumn)
from Table1

That give me the number without decimal without round it. Then I use the C0 format for report.

Now I have another problem. Yesterday, I set up Visual Studio Team Foundation Server and now I can not print my report in Color any more
Report only come black and white. Do you hear this problem before?

Thank you very much for your help,
Yumi
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)

Group: General Forum Members
Points: 84677 Visits: 41069
Ah dang... thanks for the feedback, Yumi. I've gotta remember to read the name of the forum I'm trying to answer the question on. I was thinking pure T-SQL solution which isn't appropriate for this RS case. You did it the right way... letting the service do the formatting after you've nailed the correct value.

I don't use reporting services enough to know why your reports aren't coming out in color, niow. I'd be tempted to just say "check the Windows printer settings" but I'm just not sure.

Hopefully, someone can help with that.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
becklery
becklery
SSC Veteran
SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)

Group: General Forum Members
Points: 289 Visits: 187
Hi, YumiPhx.
You can have a try of RAQ Report. As I know, it provides a lot of useful string functions for developers as shown below:


RAQ Report: Web-based Excel-like Java reporting tool
YumiPhx
YumiPhx
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 78
Jeff, Thanks for quick reply. Don't worry about confusing the forum name. I am new in Microsoft world, so you code is very helpful for me. I will apply Charindex and Nullif function next time.

Thanks again,
Yumi
YumiPhx
YumiPhx
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 78
Hi Becklery,
Very good source.
Thank you,
Yumi
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search