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?
JHausmannConnect With a Mentor 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
You will need to store it as a numeric(19)

insert into tableb(col1)
select convert(numeric(19),col1) from table1
vdAuthor Commented:
There's no such thing as a numeric 19!  Is there...
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

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

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
vdAuthor Commented:
Thanks for your thorough explanation.
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.
Thank you,
Moderator @ Experts Exchange
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.

All Courses

From novice to tech pro — start learning today.