October 21, 2005 at 9:06 pm
I need to learn how to insert a decimal point in a number without changing or adding numbers.
For example:
I have a column called "amounts" and the data I imported looks like:
12345
34566
44400
I need to change the data to insert a decimal point so the data looks like:
$ 123.45
$ 345.66
$ 444.00
Can someone give me a simple sql query to do this and maybe even insert the $ symbol.
Thank you!!
October 22, 2005 at 6:38 am
Just present it as money on the application side and you're done... you might also want to use decimal(9,2) on the server to keep that data and divide those numbers by 100.0 so that you don't have anything extra to do in the application code.
October 22, 2005 at 6:51 am
Remi beat me... This is a presentation issue, hence my second select will give you the output you want, but that is not really a SQL Server job...
CREATE TABLE #Money( [Amount] varchar(10))
INSERT INTO #Money VALUES( 12345)
INSERT INTO #Money VALUES( 34566)
INSERT INTO #Money VALUES( 44400)
SELECT (CONVERT( money, [Amount]) / 100) FROM #Money
SELECT '$ ' + CONVERT( varchar(10), (CONVERT( money, [Amount]) / 100)) FROM #Money
DROP TABLE #Money
I wasn't born stupid - I had to study.
October 22, 2005 at 9:41 am
Thank you, that worked!!
Excellent Help - Thanks again.
October 31, 2005 at 10:23 pm
>This is a presentation issue, hence my second select will give you the output you want, but that is not really a SQL Server job
It depends... if there's no presentation layer and the output is to a file because a 3rd party needs it that way, then SQL Server is perfect for the job...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply