Solved

Displaying Currency without the Decimal in SQL

Posted on 2012-03-13
5
408 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
  • 2
  • 2
5 Comments
 
LVL 45

Expert Comment

by:Kdo
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 500 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 45

Expert Comment

by:Kdo
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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