bulk insert

  • I am using the following code for bulkinsert

     

    alter Procedure SelFile

    (

     @FileName char(50)

    )

    As

    SET NOCOUNT ON

    BULK INSERT EmpInput FROM 'E:\FileTransfers\Inputs\Emp\' +@FileName+' .txt'

    GO

    but getting this error.

     

    Server: Msg 170, Level 15, State 1, Procedure SelFile, Line 29

    Line 29: Incorrect syntax near '+'.

  • Try

    EXEC('BULK INSERT EmpInput FROM ''E:\FileTransfers\Inputs\Emp\' + @FileName + '.txt''')

    Far away is close at hand in the images of elsewhere.
    Anon.

  • I tried it, it says file not found but when run bulkinsert out of SP it loads the file

  • Check and make sure ''E:\FileTransfers\Inputs\Emp\' + @FileName + '.txt''') exists on the SERVER instead of client, and check if read permission is assigned to the user running this SP

  • alter Procedure SelFile

    (

     @FileName char(50)

    )

    As

    SET NOCOUNT ON

    SET @FileName='E:\FileTransfers\Inputs\Emp\' +@FileName+' .txt'

    BULK INSERT EmpInput FROM @FileName

    GO


    Kindest Regards,

    Vasc

  • Bulk insert is expecting the E drive where the file resides to be on the SQL Server.  If it's not, you can specify the location like \\yourservername\directory\filename.txt

    There is no "i" in team, but idiot has two.

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

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