syntax needed

  • The uncommented part is not working

    declare @str_folder_path varchar(1000)='\\Dataupload'

    ,@str_media_data_file_path_csv varchar(200)='Data File.csv'

    BULK INSERT vw_pkg_dataload

    --FROM '\\Dataupload\Data File.csv'

    FROM '''' + @str_folder_path + '\' + @str_media_data_file_path_csv +''''

    WITH

    (

    FIRSTROW = 2,

    FIELDTERMINATOR ='|',ROWTERMINATOR = ''

    )

  • the FROM property for bulk insert must be a static string...it cannot be created from appended variables.

    BULK INSERT BULKACT FROM 'c:\Export_o.txt'

    to do what you want, you need everything to be dynamic SQL.

    --cursor loop?

    --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 = ''\n'',

    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 3 posts - 1 through 2 (of 2 total)

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