|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, September 23, 2011 10:32 AM
Points: 18,
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
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 4:51 PM
Points: 32,923,
Visits: 26,811
|
|
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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, September 23, 2011 10:32 AM
Points: 18,
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
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 4:51 PM
Points: 32,923,
Visits: 26,811
|
|
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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, January 14, 2010 9:09 AM
Points: 141,
Visits: 187
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, September 23, 2011 10:32 AM
Points: 18,
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, September 23, 2011 10:32 AM
Points: 18,
Visits: 78
|
|
Hi Becklery, Very good source. Thank you, Yumi
|
|
|
|