?
Solved

Displaying Currency without the Decimal in SQL

Posted on 2012-03-13
5
Medium Priority
?
415 Views
Last Modified: 2012-03-13
I have a Column in a Table that has Currency input into it.  I need to display this Currency as part of a String without the Decimal.

How do I go about doing this?

This is what I have thus far
SELECT '0000012345678901'+LTRIM(CAST(ITEMNO AS VARCHAR(20)))+''+CAST(checknet AS VARCHAR(20))+''+CONVERT(varchar(10),checkdt, 112)+CASE(ckstatus)
WHEN 'O' THEN '' WHEN 'V' THEN 'C' END +''  as Val
FROM mytable

Where you see +CAST(checknet AS VARCHAR(20)) is where I need to extract the information from that Column and display it without the Decimal.

Thank you
0
Comment
Question by:Rmumpower00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 37717228
Hi Rmum,

Probably the easiest way is just to cast it to an integer.

  SELECT cast (column * 100 as INTEGER) FROM ...

That will preserve the two decimal places and display the entire value.



Good Luck,
Kent
0
 

Author Comment

by:Rmumpower00
ID: 37717262
Kent,
Could you possibly put what you're talking about into the string that I listed?
0
 
LVL 2

Accepted Solution

by:
musickmann earned 2000 total points
ID: 37717278
Would using the REPLACE (string_expression, search_string,  replacement_string) function work for you? Might look something like this:


 REPLACE (CAST(checknet AS VARCHAR(20)), '.',  '')
0
 

Author Comment

by:Rmumpower00
ID: 37717288
Musickmann That worked!!!!!!!!!!

Thank you!
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 37717299
SELECT
  '0000012345678901'+LTRIM(CAST(ITEMNO AS VARCHAR(20)))+''+
  cast (cast (column * 100 as INTEGER) as varchar(20) +
  ''+CONVERT(varchar(10),checkdt, 112)+
  CASE(ckstatus) WHEN 'O' THEN '' WHEN 'V' THEN 'C' END +''  as Val
FROM mytable

Though the double casting might make musickmann's suggestion to use REPLACE easier.


Kent
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

777 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