Pervasive
Sign in | Join | Help
in

Importing data into MS SQL, need to add a string to a field

Last post 07-02-2008 5:45 AM by koke. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-01-2008 2:26 PM

    • koke
    • Not Ranked
    • Joined on 02-16-2007
    • Posts 2

    Importing data into MS SQL, need to add a string to a field

    I have a customer that has two AOD companies that have a ID field with the same series of numbers in them.  In order to not overwrite one set of records from the second set of records, I want to add a string to the data in the ID field.

    This is what I have tried to do:

    SELECT "'RW' + CONVERT(Profile_ID, SQL_CHAR (10))" AS Profile_ID

    I have also tried:

    SELECT "'RW' + CAST(Profile_ID AS nvarchar (10))" AS Profile_ID

     Both of these cause an error with the ODBC driver for PSQL saying the there is an invalid column:

    Detail: ERROR [HY000] [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Error in expression: 'RW' + CAST(Profile_ID AS nvarchar (10))
    ERROR [42S22] [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Invalid column name: ''RW' + CAST(Profile_ID AS nvarchar (10))'.

     

    This seems like it should be a simple thing.  Any guidance? 

     Thanks!

    Mike Kokinda

  • 07-01-2008 2:37 PM In reply to

    • Linda
    • Top 500 Contributor
    • Joined on 03-04-2008
    • Posts 11

    Re: Importing data into MS SQL, need to add a string to a field

    CONVERT should not have a length associated with the data type. 
    CAST should not have SQL_ in front of the datatype.  Also, it needs to be either CHAR, VARCHAR, or LONGVARCHAR.

    These statements worked correctly:

    create table mike (Profile_ID integer, name char(10));
    insert into mike values (1, 'abc');

    select * from mike;

    SELECT 'RW' + CONVERT(Profile_ID, SQL_CHAR) as Profile_ID from mike;

    SELECT 'RW' + CAST(Profile_ID AS VARCHAR(10)) as Profile_ID from mike;

  • 07-02-2008 5:45 AM In reply to

    • koke
    • Not Ranked
    • Joined on 02-16-2007
    • Posts 2

    Re: Importing data into MS SQL, need to add a string to a field

    Thanks Linda, the import did work with the exception that it brought in Data twice.  Once with the RW string added to the Profile_ID data and then again with out the RW.  I have to pull apart the entire import to see where the second set of data comes in at....

     I appreciate the help.  It seems the nvarchar was the problem with my previous attempts.

     

    Koke (Mike)

Page 1 of 1 (3 items)
© 2008 Pervasive Software Inc. All Rights Reserved.