Import Question (sorry posted this in wrong forum)

  • Hi all, 

    Sorry I realise I have posted this in the admin forum as well.

    I have a simple problem really, but my knowledge is very limited at the moment.

    My question is as follows.

    I have two tables, 1 in database A and the other in Database B.  Each table is identical except that the table in A has a column which must be int, whilst the column in B is varchar but does contain numeric values (i.e 68900, 67800 etc).

    How can I import only the numeric values into table A from Table B.

    I can figure out the import of data, but my sql knowledge as I have said is very limited and so I need your expertise.

    Cheers.

  • You can use the ISNUMERIC() function. The code would look something like this (You would be in Database_A when running it) :

     

    insert into TableA (ColumnA)

    select ColumnB

    from Database_B.dbo.TableB

    where ISNUMERIC(ColumnB) = 1

     

    Cheers,

     

  • Also, if ColumnA must be of datatype int, use the CONVERT/CAST function to convert ColumnB to the correct datatype. i.e.:

    insert into TableA (ColumnA)

    select CONVERT(int, ColumnB) /* or CASE(ColumnB AS int) */

    from Database_B.dbo.TableB

    where ISNUMERIC(ColumnB) = 1


    ----------------------------------------
    Pascal Dobrautz
    www.sqlassi.net

  • Hi all,

    Thanks for your help, I have managed to get whet I wanted.

    You gave me some ideas and that is very welcome.

    Cheers

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply