1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] In SQL Server Management Studio, how do I ignore the first column in a table when bulk...

Discussão em 'Outras Linguagens' iniciado por Stack, Agosto 16, 2021.

  1. Stack

    Stack Membro Participativo

    Keep in mind that I am student, so I can not modify the csv file. It must also be coded and no "special tools" are allowed. I have these statements in SQL:

    Schema and table creation:

    CREATE SCHEMA IA;
    GO

    CREATE TABLE IA.CONTACTS
    (
    CONT_GUID UNIQUEIDENTIFIER PRIMARY KEY NOT NULL,
    CONT_FNAME VARCHAR(100) NOT NULL,
    CONT_LNAME VARCHAR(100) NOT NULL,
    CONT_DOB DATE,
    CONT_CALLS INTEGER
    );


    Attempt to bulk insert from a csv file:

    BULK INSERT IA.IA.Contacts
    FROM 'C:\Users\k20\Desktop/IA.CONTACTS.csv'
    WITH
    (FIRSTROW = 2,
    KEEPIDENTITY,
    FIELDTERMINATOR = ',',
    ROWTERMINATOR = '\n');


    I get this error:


    Msg 4864, Level 16, State 1, Line 3
    Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (CONT_GUID).

    Msg 4864, Level 16, State 1, Line 3
    Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 3, column 1 (CONT_GUID).

    .... and so on, for every row in the csv file

    I have 4 columns in my csv file, but 5 in my table. How do I ignore the first one from the table, CONT_GUID?

    EDIT:

    CONT_FNAME CONT_LNAME CONT_DOB CONT_CALLS
    Mary May 1/25/1980 2
    John James 1/13/1978 3
    Martin Merriweather 4/25/1988 1
    James Johns 6/13/1990 1
    Jerry Jacobs 11/11/1996 1
    Madelyn Mace 3/30/1995 2
    Bruce Blake 1/30/1970 4
    Brian Brown 12/4/1980 2
    Charlie Childress 2/13/1987 3
    Ray Rhodes 12/23/1989 1
    William Willis 11/13/1985 1
    Herman Hughes 3/1/1980 2
    Steve Stevens 5/12/1984 2
    Daryl Dixon 9/25/1983 3
    Abe Avery 8/24/1987 5
    Kevin Carlyle 10/15/1975 3
    Sean Shaffer 10/25/1977 3
    Peter Piper 8/6/1974 3
    Oscar Oosker 7/2/1973 2
    Tom Townsend 6/6/1965 1
    Victor Vaughn 6/13/1966 1
    Nick Nice 7/12/1968 1
    Sally Soose 6/12/1984 1
    June Johnson 12/16/1984 1


    It's directly from the csv file. Commas with no spaces are used as the separators.

    Continue reading...

Compartilhe esta Página