on 02-17-2016 3:40 AM
Hi, Experts
There is a table column defined as numeric (126,38).
How to get max precision/width and scale of values actually inserted into the column ?
Thanks in advance
Hi,
I would use string functions to solve this. I know this is not really fast. Currently I don't have an IQ so I can't provide the statements.
So for the "whole length": convert / cast the value to char and then use length or char_length function.
For scale you can use the same approach, find the "." with charindex, create a substring, and then the length function again.
I think the following would be faster: subtract column_value - int(column_value) and then convert / cast to string and use length function again.
Best regards,
Juergen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try select below based on Juegen's idea. It works ONLY for values without zeros digits in the right.
Example for input value 1234567.123 :
select (CHAR_LENGTH(cast(1234567.123 as varchar(150)) ) -1) as Num_Precision, (CHAR_LENGTH( cast(1234567.123 as varchar(150)) ) - LOCATE(1234567.123, '.') ) as Num_Scale FROM iq_dummy
Result :
NumPrecision, NumScale
10, 3
For numbers like 1234567.000 or 1234567.01000, you may need modify the statement or find out another one.
The reason is cast function truncates the right zeros when converting to varchar :
cast(1234567.000 as varchar(150)) gives 1234567
cast(1234567.01000 as varchar(150)) gives 1234567.01
Regards, Tayeb.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.