Solved

Is there a SQL Server equivalent to the format(X,Y) in MySQL?

Posted on 2007-03-21
6
220 Views
Last Modified: 2008-01-09
Is there an equivalent function in SQL Server to the format(X,Y) in MySQL?

I want to display a numeric value with its comma separators.

Many Thanks
0
Comment
Question by:inghfs
[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
  • 3
  • 3
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18764712
yes and no.
you can try to use the convert function:
select convert(money, yourfield) from yourtable

however, the convert function is far from the flexibility you are used to.
you should write your own format function, eventually based on the results of convert() function.
0
 

Author Comment

by:inghfs
ID: 18764748
Do you have a similar pre-written function which would be amended; I'm looking into formatting the field from 1000 to 1,000.

Thanks
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18764811
you can check out this code:
select replace(convert(varchar(10),convert(smallmoney, 1000),3), ".00", "")
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:inghfs
ID: 18764906
Sorry, I was just using 1000 to 1,000 as an example. How would I do this for an arbitrary number. Similar to doing FORMAT(field, '#,###,###,###') in MySQL
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18764989
as said, with arbitrary format, this is not available.
my suggestion above should do your requested format
0
 

Author Comment

by:inghfs
ID: 18764996
Okay, Many Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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