BULK INSERT

  • I'm trying to do this

    declare @file1 char(20)

    declare @sql varchar(2000)

    select @file1 = rtrim(file1) from dates

    SET @sql = "BULK INSERT temp FROM @file1 WITH (FIELDTERMINATOR = ',') "

    exec (@SQL)

    problem is...@file1 is a variable and will change everyday...and that Bulk insert statment do not alow the variable there..

    any idea??

    thanks

  • SET @sql = 'BULK INSERT temp FROM ' + @file1 + ' WITH (FIELDTERMINATOR = '','') '

    exec (@SQL)

    Edited by - mromm on 06/25/2003 10:56:36 AM

  • You need to use the value of the variable @file to create the dynamic statement i.e.

    SET @sql = "BULK INSERT temp FROM '" + @file1 + "' WITH (FIELDTERMINATOR = ',') "

  • the @file1 is e:\smdr\03062300.15s

    from mromm statement running but said

    Server: Msg 170, Level 15, State 1, Line 1

    Line 1: Incorrect syntax near 'e:'.

  • Just fix a sistax error, I did not test that code. Also, avoid using doublr quotes: they are not standard:

    SET @sql = 'BULK INSERT temp FROM ''' + @file1 + ''' WITH (FIELDTERMINATOR = '','') '

    exec (@SQL)

  • thanks alot...it's working

    THANK YOU

Viewing 6 posts - 1 through 5 (of 5 total)

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