smsh
smsh

Reputation: 305

What is the data type for Currency in SQL Server?

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?

Upvotes: 10

Views: 84386

Answers (4)

Ashutosh
Ashutosh

Reputation: 27

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

Upvotes: 0

Alfaiz Ahmed
Alfaiz Ahmed

Reputation: 1728

DECLARE @Price Decimal(18,2) = 11.23
SELECT FORMAT(@Price,'c','en-US') AS 'CURRENCY IN US Culture'

Upvotes: 11

Gopal Krishna Ranjan
Gopal Krishna Ranjan

Reputation: 878

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.

Upvotes: 3

Paolo
Paolo

Reputation: 2254

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.

Upvotes: 4

Related Questions