# Convert char 19 column to integer

I have a column of numbers in Table A of data type char (length 19). I would like to copy the entries in this column to another table, Table B, to a column of type integer (long integer).
What would be a good way to do this?
###### Who is Participating?

Commented:
Yes, there is. A numeric field that uses from 17-19 places of precision uses 9 bytes of storage. The maximum precision is 38, which uses 17 bytes of storage. NUMERIC is known as an "exact" numeric datatype, FLOAT and REAL are "approximate" numeric datatypes Float's can hold a maximum of 15 digits of precision, which is significantly less than the 38 places a numeric field is capable of using.

NUMERIC(precision, scale) is the same as DECIMAL (precision,scale). They are *both* present in SQL only for ANSI compatibility. Precision is used to store the total length of the number (not including the "sign") and scale can never be larger than the precision.

You have to be aware that if your data (col1) contains alphabetic characters, the conversion WILL not happen. If it's a string of digits, it will work.

simonsabin answer is/was correct, the thing I would change is the conversion function (although it does not make his answer incorrect) :

insert into tableb(col1) select convert(numeric(19,0), col1 from table1
0

Commented:
You will need to store it as a numeric(19)

i.e
insert into tableb(col1)
select convert(numeric(19),col1) from table1
0

Author Commented:
There's no such thing as a numeric 19!  Is there...
0

Commented:
One final thing, if your the string of characters that's in your table is less than 11 digits (in the field defined as char(19)) you could do:

insert into tableb(col1)
select convert(int,col1) from table1 where isnumeric(col1) = 1
0

Commented:
JHausman

I know you are new so I will let you off but be aware you should never post an answer if someones comment is correct. You should only post an answer if you have the definitive answer and no one has already said it in a comment/answer before. Or you have been asked to post an answer
0

Author Commented:
0

Commented:
Thanks...
0

Commented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp

Thank you,
Moondancer
Moderator @ Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.