SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 CAST Statement in a query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tgunther
Starting Member

4 Posts

Posted - 04/11/2007 :  13:21:25  Show Profile  Reply with Quote
When using a CAST statement in a query to CAST a decimal field as a char field, is there a way to prevent the .00 from being automatically generated? For instance if I have a value of 1925 in my decimal field when I CAST it as a char field it displays as 1925.00, this being a problem as 1925 actually represents $1,925K. Thank you in advance for any help you may be able to give.

sshelper
Posting Yak Master

216 Posts

Posted - 04/11/2007 :  13:23:41  Show Profile  Visit sshelper's Homepage  Reply with Quote
One option is to CAST the decimal field to INT first, then to CHAR:

SELECT CAST(CAST(YourDecimalColumn AS INT) AS VARCHAR(10)) FROM YourTabl

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17587 Posts

Posted - 04/11/2007 :  18:58:38  Show Profile  Reply with Quote
or convert to varchar then use replace() to remove the '.00'.

select replace(convert(varchar(10), YourDecimalColumn), '.00', '')



KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17587 Posts

Posted - 04/11/2007 :  19:00:45  Show Profile  Reply with Quote
Do you have to do this in SQL ? Can you do this in your font end application ?


KH

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000