BULK INSERT issue

  • Hi,

    I want to use a bulk insert statement in a stored procedure, but instead of using a string to pass the location of the file I want to use a parameter to pass in the file name.

    Below is my code but I get an incorrect syntax error with the line: from @fileLocation

    Does this mean that you can't use a parameter in this situation? Or have I just coded it incorrectly?

    DECLARE @fileLocation varchar(100)

    SET @fileLocation = 'C:\ExciteUpload\Amazon\' + @fileName

    BEGIN TRAN

    Bulk Insert Amazon_Orders

    from @fileLocation

    with

    (ROWTERMINATOR ='\n',

    BATCHSIZE = 50000,

    CODEPAGE = 'ACP',

    FIRSTROW = 2)

    COMMIT TRAN

    Any help would be much appreciated.

    Cheers

    Reet

  • Have you tried putting everything in dynamic sql and run it like that??

     

    I think it's like the problem with : "use @MyDbname" >> can't work without dynamic sql.

  • Cheers

    Seems to have done the trick!

  • Great.  I'm still opened to other suggestions since I ain't no expert in the matter.

  • You are now 'cause that's the way to do it...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • If you insist .

    I'll let Jeff explain this new nickname .

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

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