Solved

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

Posted on 2007-03-21
6
208 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
  • 3
  • 3
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
you can check out this code:
select replace(convert(varchar(10),convert(smallmoney, 1000),3), ".00", "")
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:inghfs
Comment Utility
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 142

Expert Comment

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

Author Comment

by:inghfs
Comment Utility
Okay, Many Thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now