Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 CAST Statement in a query

Author  Topic 

tgunther
Starting Member

4 Posts

Posted - 2007-04-11 : 13:21:25
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 - 2007-04-11 : 13:23:41
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)

17689 Posts

Posted - 2007-04-11 : 18:58:38
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)

17689 Posts

Posted - 2007-04-11 : 19:00:45
Do you have to do this in SQL ? Can you do this in your font end application ?


KH

Go to Top of Page
   

- Advertisement -