Import excel file into sql  URGENT!!!!!!!!!

Posted on 2006-04-11
Last Modified: 2008-02-01
I have multiple excel file that I need to get into sql.   I need the file name to be a variable passed by a stored procedure.  I part I am having a problem with is how to I get it into a sql table.  I know I need to create the temp table, but when I try a bulk insert the line all runs together into one column.  I also need to parse out the lastname and first name when uploading.  I'm really desperate to get this working today.  Any help would be greatly appreicated.

The rows in my file are set up as

Name               DOB      Age      Chart#      VisitDt      Provider      Office      Diag1      CPT      SSAN          Sex      Address             City           State      Zip      Rating
Test,Justine      13-May-61      44      s1234      10-Jan-06      d59      mfc      296.7      99211      512-41-4444  m      123 Test Street Test City  CO      12457      z
Question by:running32
    LVL 18

    Expert Comment

    How do you do the bulk insert? How do you store the Excel file? What are your seperators?

    Author Comment

    I am storing the excel file on the sql server.

    The csv is comma delimited.

    I thought I could do the bulk insert as  but it all runs into one column.

    drop table [HealthDistrict].[dbo].temp2

    CREATE TABLE [HealthDistrict].[dbo].[Temp2] (
    [strName] nvarchar (255) NULL,
    [dtmdob] smalldatetime NULL,
    [lngage] float NULL,
    [strchart] nvarchar (255) NULL,
    [dtmvisit] smalldatetime NULL,
    [strprovider] nvarchar (255) NULL,
    [stroffice] nvarchar (255) NULL,
    [strDiag] nvarchar (255) NULL,
    [strcpt] nvarchar (255) NULL,
    [strssnum] nvarchar (255) NULL,
    [strsex] nvarchar (255) NULL,
    [straddress] nvarchar (255) NULL,
    [strcity] nvarchar (255) NULL,
    [strState] nvarchar (255) NULL,
    [strzip] nvarchar (255) NULL,
    [strrating] nvarchar (255) NULL
    BULK INSERT temp FROM 'd:\download\2006.csv' WITH (FIELDTERMINATOR = ',', FIRSTROW=2)
    LVL 11

    Accepted Solution

    HI I think you can Use OpendataSource function to Achive this Export thing..

    SELECT *
    FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
    'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 8.0')...xactions

    Here you can change file name dynamically
    LVL 18

    Assisted Solution

    Don't use comma's as separators, not unless you also quote your values. The example record you give would break your structure because Test, Justine would be viewed as 2 fields.

    Author Comment

    Thisis the error I get when I use the insert.  Thanks

    Server: Msg 7314, Level 16, State 1, Line 4
    OLE DB provider 'Microsoft.Jet.OLEDB.4.0' does not contain table 'test'.  The table either does not exist or the current user does not have permissions on that table.
    OLE DB error trace [Non-interface error:  OLE DB provider does not contain the table: ProviderName='Microsoft.Jet.OLEDB.4.0', TableName='test'].

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    The steps for moving the system databases to a new location are documented in the following technical article: However sometimes after the moving process is finished, though SQL i…
    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now