none
Using Bulk Insert with DBF files. RRS feed

  • Question

  • Hey Guys.

    I am new to SQL Server and am trying to write a procedure to import 500 DBF files. (<-- This will happen every two weeks... so looking to automate it a little bit...) I want the procedure to loop through the folder and insert each DBF file into its own table. Here is what I have so far: (I am thinking to finish this procedure and write a batch that loops through the file and runs the procedure on each one.)


    ----------------------------------------
    create table [tempDBF](
        [DOC_NO] varchar(14) not null,
        [FAPC] varchar(5) not null,
      ...etc
     
    );

    create table ['"+@fileName+'"](
          [DOC_NO] varchar(14) not null,
        [FAPC] varchar(5) not null,
      ...etc
    );


    CREATE PROCEDURE ps_DBF_IMPORT
    @pathName varchar(200)
    @fileName varchar(100),
    AS

    DECLARE @sqlQuery varchar(2000)
    BEGIN
        SET @sqlQuery = "BULK INSERT tempDBF FROM '"+@path+@fileName+"' WITH (--How do I specify DBF format?--)
    END

    EXEC (@sqlQuery)

    INSERT INTO '"+@fileName+"'
    SELECT *
    FROM tempDBF
    ------------------------------------------

    I am not sure how to set the BULK INSERT for DBF format. Any ideas?

    Any help would be greatly appreciated.

    Thanks,

    -Michael
    Tuesday, February 20, 2007 4:05 PM

All replies

  • Bulk insert is only for text files.  You cannot directly import DBF files.  Look at SSIS to write a package to import the files.  That is what SSIS is for.

    Tuesday, February 20, 2007 4:41 PM
    Moderator