SQL - UPDATE query (moving decimal points)

时间:2015-09-01 21:42:34

标签: sql decimal sybase

I need an update query to take a particular field and move decimal points.

SELECT amount FROM transaction table WHERE id = 20

Amount 
12987

Need an update query

UPDATE transaction
SET amount = amount/100
WHERE id = 20

Will this work?

SELECT amount FROM transaction table WHERE id = 20

Amount
129.87

1 个答案:

答案 0 :(得分:0)

I suspect that amount is stored as an integer. If you want decimal places, you first need to change it to something that supports decimals. Perhaps:

alter table transaction alter amount decimal(19, 4);

Then this should work:

Update transaction
    set amount = amount / 100.0
    where id = 20;