sql server 2005 express - Invert a decimal into a query -



sql server 2005 express - Invert a decimal into a query -

i have column currency displayed numeric field. so, '$3.15' recorded '315'. when doing query, i'm looking place decimal 2 places these numbers 2066 becomes 20.66 , 315 becomes 3.15

i know it's easy cast or convert, have searched around , cannot find solution. i'm building query in sql server 2005 express.

thanks in advance help!

the problem when split 2 integer values, result integer too, , truncated. (called: integer math)

select 2066/100 -- output 20

to avoid truncation, should cast 1 of arguments datatype, can represent result value:

select 2066 / convert(decimal(19,2), 100) -- output 20.660000

to forcefulness precision , scale, shoud convert result too:

select convert(decimal(19,2), (2066 / convert(decimal(19,2), 100))) -- output 20.66

as general advice:

to store these values, utilize decimal or numeric info types insted of integers. take precision , scale fit needs (including summarizing data, calculating averages, , on) all formatting should done when display info (in application) insted of in database server.

sql-server-2005-express

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -