Here is a simple example:
Is there a way to cast a decimal to a variable scale? Business case: Some currency amounts are rounded to 3 decimals in some cultures, others to 2. asked 17 Mar '16, 02:45 tzup |
EXECUTE IMMEDIATE is your friend here if you want to use CAST with a DECIMAL and a variable scale. BEGIN DECLARE three INTEGER; SET three = 3; -- Working SELECT CAST(32.3369 as DECIMAL(30, 3)); -- Now working EXECUTE IMMEDIATE 'SELECT CAST(32.3369 as DECIMAL(30, ' || three || '))'; END For ROUND(), Dmitri's approach is strongly recommended... answered 17 Mar '16, 03:58 Volker Barth Good tip on using EXECUTE IMMEDIATE. Thanks!
(17 Mar '16, 05:20)
tzup
|