Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

question about number format

 
   Database Help (Home) -> Programming RSS
Next:  select from two tables  
Author Message
Kevin

External


Since: Jan 11, 2008
Posts: 53



(Msg. 1) Posted: Tue May 27, 2008 7:56 am
Post subject: question about number format
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I want to format the following numbers

189800 to $190K
2501000 to $2,501K

I used the following query (not sure what other way I can do)
but the problem is I don't know how to add comma.
is there an easier way to format the numbers in query?


SELECT '$'+ CONVERT(VARCHAR,CAST(ROUND(CONVERT(VARCHAR, 2501000/1000),0) AS
INT)) + 'K'


Thanks

 >> Stay informed about: question about number format 
Back to top
Login to vote
Razvan Socol

External


Since: Feb 03, 2008
Posts: 219



(Msg. 2) Posted: Tue May 27, 2008 8:18 am
Post subject: Re: question about number format [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hello, Kevin

Try something like this:

CREATE TABLE #T (N INT)
INSERT INTO #T VALUES (189800)
INSERT INTO #T VALUES (2501000)

SELECT N, '$'+ REPLACE(CONVERT(varchar(10),
CONVERT(money,ROUND(N/1000.,0)),1),'.00','') + 'K'
FROM #T

DROP TABLE #T

--
Razvan Socol
SQL Server MVP

 >> Stay informed about: question about number format 
Back to top
Login to vote
--CELKO--

External


Since: Jan 11, 2008
Posts: 1089



(Msg. 3) Posted: Tue May 27, 2008 11:18 am
Post subject: Re: question about number format [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>> I want to format the following numbers .. <<

In a client-server architecture, formatting is done in the front end
and not the database. You are still writing COBOL, where the data is
formatted in the file system and the files +application programs are
monolithic.
 >> Stay informed about: question about number format 
Back to top
Login to vote
John Bell

External


Since: Jun 01, 2004
Posts: 652



(Msg. 4) Posted: Tue May 27, 2008 5:25 pm
Post subject: Re: question about number format [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Kevin" wrote in message

>I want to format the following numbers
>
> 189800 to $190K
> 2501000 to $2,501K
>
> I used the following query (not sure what other way I can do)
> but the problem is I don't know how to add comma.
> is there an easier way to format the numbers in query?
>
>
> SELECT '$'+ CONVERT(VARCHAR,CAST(ROUND(CONVERT(VARCHAR, 2501000/1000),0)
> AS
> INT)) + 'K'
>
>
> Thanks
>
Hi Kevin

This is usually left to the client application rather than the database.

John
 >> Stay informed about: question about number format 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
isqlw results number format -

format number with thousand-separator - is there a built in function in sql server 2005 that will format a number with commas as the thousand-separator? ie., here's what i want to do: input=1000 output=1,000 or input=1000000 output=1,000,000 if there isn't a built-in function, can someone....

Question: Is there a way to count the number of executions.. - Hello, Does anyone know if it's possible to keep track of the number of times a stored procedure is run? (by any and all users.) I want to try to clean up an existing legacy system which is full of old stored procedures. Many of which I believe are...

URGENT: Question about deleting a large number of rows - I need to run a single query to delete a large number of rows (hundreds of thousands of rows). Will this grow the transaction log by a large amount? If so, how do I go about temporarily suspending transaction logging, either in the query or by using....

DateTime Format - Hello All, Is it possible to store the date as ' 02 - Apr - 2006 ' in the SQL datetime field? If it is please tell how to do. Thanks, karthick
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]