BULK insert problem

  • Hello,

    I have a proplem with BULK in stored procedures.

    I want to do a BULK from a file (.CSV) wich name changes every day. So I have an attribute “@FileName” in order to change the name every single day.

    BULK INSERT dbo.TableName

    FROM @FileName

    WITH ( FIELDTERMINATOR=’;', ROWTERMINATOR=’\’)

    But it gives me an error telling that there’s a sintax error after FROM. I have tried with all kind of punctuation (’,”,`,´,+)

    It would be gratefull if some one could answer to my question.

    Thanks in advance

  • saved in my snippets: bulk insert will not accept a variable, so you need to use the EXEC command instead:

    --bulk insert won't take a variable name, so make a sql and execute it instead:

    set @sql = 'BULK INSERT BULKACT FROM ''' + @path + @filename + ''' '

    + ' WITH (

    DATAFILETYPE = ''char'',

    FIELDTERMINATOR = '','',

    ROWTERMINATOR = '''',

    FIRSTROW = 2

    ) '

    print @sql

    exec (@sql)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

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