Specify columns to import using BULK INSERT

  • I have a BULK INSERT sql file that executes serveral stored procedures.  The file is a CSV and all I need are three columns out of 15 that are inside this file. 

    How do I specify the three columns in the CSV file using the BULK INSERT t-sql? 

    Here is one of my scripts:

    CREATE PROCEDURE ComputedAttributesLoad

    (

      @FilePathName varchar(100)

    )

    AS

    TRUNCATE TABLE ComputedAttributes

    DECLARE @sql varchar(1000)

    BEGIN

      SET @sql = "BULK INSERT ComputedAttributes FROM '" +@FilePathName+ "' WITH (FIELDTERMINATOR = ',')"

    END

    EXEC(@SQL)

    GO

     

    Thanks in advance,

    Harry

  • Use the FORMATFILE to specify what you want from it

    HTH

     


    * Noel

  • Thanks, HTH.  I will look up the usage online and give it a try.

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

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