Conversion of the value of the Numeric field to VARCHAR to save the invalid zero after the decimal point?

xiaoxiao2021-03-06  50

Example 1Declare @A Numeric (6,3) set @ a = 6.5

- Convert SELECT original value = @ a, after conversion = cast (Cast (@a as float) as varchar)

/*--result

After the original value conversion ------------------------------------ 6.500 6.5

(The number of rows affects is 1 line) - * / ==================================== ==================== - Example 2

Declare @a numeric (6, 3) set @ a = 6.5

- Convert SELECT original value = @ a, after conversion = left (@ a, len (@a) -patindex ('% [^ 0]%.%', Reverse (@a)) 1)

/*--result

After the original value conversion ------------------------------------ 6.500 6.5

(The number of rows affects is 1 line) - * /

转载请注明原文地址:https://www.9cbs.com/read-81984.html

New Post(0)