Solved

How can I find out the precision and scale information of a decimal column from the SYSCOLUMNS table?

Posted on 2011-09-13
16
753 Views
Last Modified: 2013-12-24
Is it possible for me to run a query to find out the precision and scale information of a decimal column?  Thanks.
0
Comment
Question by:thomaszhwang
  • 8
  • 6
  • 2
16 Comments
 
LVL 7

Expert Comment

by:d507201
ID: 36532743
I'm not an expert, but  from this page it looks like select min(fieldName), max(fieldName) might tell you what you need.

http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.odbc.doc/odbc72.htm
0
 

Author Comment

by:thomaszhwang
ID: 36532799
Sorry for the confusion.  What I meant by Precision and Scale of a Decimal field is the Precision and Scale you specified when you define a Decimal field in a table.

Now the problem is after someone else created the table, is there a way to find out the Precision and Scale information?

Thanks.
0
 
LVL 7

Expert Comment

by:d507201
ID: 36532865
Yes, it seems like that sort of think should be captured somewhere in a system table like syscolumns, but I don't know where.  I scrolled down thru the list of system tables, looked at a few, but didn't find anything.  Seems like that sort of thing should be in syscolumns but itsn't.  

Good luck!
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36532873
In MS SQL Server, there are columns xprec and xscale, not sure what the equivalents are for Informix; however, you can try this and see if it works:

SELECT name, xprec, xscale 
FROM SYSCOLUMNS 
WHERE name = 'column_name'
;

Open in new window

0
 

Author Comment

by:thomaszhwang
ID: 36532877
If you look at the Info section in DBACCESS, you can actually see the Precision and Scale of a Decimal column, so the information should be somewhere.
0
 

Author Comment

by:thomaszhwang
ID: 36532899
@mwvisa1

No, I'm sure it's not in the SYSCOLUMNS table.  Thanks though.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36532910
It looks like it doesn't have those columns. It appears to just store the coltype, but maybe the information is hidden in the extended values columns...I am searching to see if I spot anything relevant.

http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqlr.doc/sqlrmst41.htm

In the reference, it points to $INFORMIXDIR/incl/esql/sqltypes.h that has all the coltype codes. Maybe there is a variation on the type code based on the selected. I know the length is often calculated based on the precision/scale combination but doesn't necessarily help you get to what you want. Hmm.
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36532934
Okay, found it: http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqlr.doc/sqlrmst41.htm

The collength value for a MONEY or DECIMAL (p, s) column can be calculated using the following formula:
(precision * 256) + scale

Open in new window


So, if (p * 256) + s = l ==> (l - s)/256 = p and then l - p*256 = s.
0
 

Author Comment

by:thomaszhwang
ID: 36532935
What I really want is to recreate this database (schema only) on another server, if you can help with this.  Thanks.
0
 

Author Comment

by:thomaszhwang
ID: 36532946
In order to solve this equation, scale must be less than 256, is this true?
0
 

Author Closing Comment

by:thomaszhwang
ID: 36532980
You are right.  Thanks!
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36532997
First, have you tried simply taking a backup and doing a restore? Additionally, Informix has Export and Import commands: http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.ii.doc/start/iiymgimportref.htm

Given this question is very specific to finding "precision and scale" in SYSCOLUMNS, it probably is not attracting folks with the idea that you are wanting to copy a database; therefore, a secondary recommendation would be for you to start a *new* question with that as the heading with clear details on what you are trying to do. Hopefully, the folks more versed in that will assist you if my help above doesn't help.
0
 

Author Comment

by:thomaszhwang
ID: 36533002
I have already created a separate thread.  Unfortunately I don't have permission to do an export...
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36533008
Bummer (on permissions). Hopefully you get some good responses in new thread.

Best regards and happy coding,
Kevin
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36533086
"In order to solve this equation, scale must be less than 256, is this true?" < Yes, btw. Since scale is the number of digits after the decimal, it can't be higher than precision. Precision in Informix is bound to <= 32; therefore, you can guarantee that scale is <= 32, making the formula to solve this:

MOD(l, 256) = s <== l modulus 256 ==> remainder is s (scale)
(l - s)/256 = p <== using s from above
0
 

Author Comment

by:thomaszhwang
ID: 36533601
Thanks.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question