Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 633
  • Last Modified:

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
0
running32
Asked:
running32
  • 2
  • 2
2 Solutions
 
SjoerdVerweijCommented:
How do you do the bulk insert? How do you store the Excel file? What are your seperators?
0
 
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
)
ON [PRIMARY]
GO
BULK INSERT temp FROM 'd:\download\2006.csv' WITH (FIELDTERMINATOR = ',', FIRSTROW=2)
0
 
Ved Prakash AgrawalDatabase Consultant/Performance ArchitectCommented:
HI I think you can Use OpendataSource function to Achive this Export thing..

INSERT INTO TABLENAME
(Columnnames)
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
0
 
SjoerdVerweijCommented:
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.
0
 
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'].
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now