Solved

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

Posted on 2007-03-21
6
225 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
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…

717 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