11

What is the data type to the currency value in SQL Server.

e.g: I want to store $11.23.

Can I use money type and addtionally will it store the $ symbol?

4
  • 1
    any numeric data type will not store any symbol if you put symbol you have to phase lot of problem to calculate that amount Commented Sep 10, 2015 at 8:56
  • possible duplicate of Best data type for currency values Commented Sep 10, 2015 at 8:59
  • possible duplicate of Should you choose the MONEY or DECIMAL(x,y) datatypes in SQL Server? Commented Sep 10, 2015 at 9:30
  • There's no point in using money, it doesn't store any currency info, has limited range and a hard-coded precision of 4. Typically a decimal with a specific range and precision is used, eg decimal(9,2) specifies 9 digits, 2 of which are decimals. money more for for compatibility with VB6 and OLEDB than anything else Commented Sep 10, 2015 at 9:38

4 Answers 4

11
DECLARE @Price Decimal(18,2) = 11.23 SELECT FORMAT(@Price,'c','en-US') AS 'CURRENCY IN US Culture' 
Sign up to request clarification or add additional context in comments.

Comments

5

answering to the question in the title, the datatype for currency is MONEY.

the money datatype will store the information only, without the format: in your example the information is 11.23 so that's what is saved into the database.

the $ sign is part of the format so it will not be stored into the money field.

the usual solution is to have a MONEY field for the amount and a VARCHAR field for the currency symbol/name.

3 Comments

money isn't useful as it doesn't store any currency info. It's simply a decimal type with less precision than a decimal. It also doesn't allow you to specify precision, eg when values are allowed to only have 2 decimals. What does 21.3455 $ mean?
@PanagiotisKanavos that's your opinion, mine is different. if you need to change precision and scale then go with other datatypes but if MONEY (knowing its specifications) fits then can be a valid choice as any other datatype.
3

I think the best way to store the currency is to use either NUMERIC or DECIMAL data types as these values participates in calculations. If we use NVARCHAR to allow the storage with symbol like ($), it will cost extra during calculations when use in WHERE clause. We can choose the precision and scale accordingly.

Comments

0

it should be DECIMAL(,) OR NUMERIC in SQL. eg DECIMAL(20,2)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.