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

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
Who is Participating?
Ved Prakash AgrawalDatabase Consultant/Performance ArchitectCommented:
HI I think you can Use OpendataSource function to Achive this Export thing..

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
How do you do the bulk insert? How do you store the Excel file? What are your seperators?
running32Author Commented:
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)
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.
running32Author Commented:
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'].
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.