Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Import xlsx into SQL Table

$
0
0

I am working on creating a stored procedure for importing export files from our client system into our Human Resource system. I am running into an error on a couple of issues.

1. When pulling data from the excel spreadsheet, it wants to write into my primary key, which is set to auto increment (processID). On the excel spreadsheet this field is left blank.

2. When the path to the file is specified in

'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\Export\ICT_12042013.xlsx',
'SELECT * FROM [sheet1$]'

I would like to set it to use a parameter provided by the user that will allow them to specify exactly which file will be imported. I have attempted to do it this way

'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=' + @pathToFile,
'SELECT * FROM [sheet1$]'

I have had no luck with this.

Here is my complete stored procedure. Any help would be greatly appreciated.

Thanks,

USE [Tempus_Fugit]
GO
/****** Object:  StoredProcedure [dbo].[loadBranchExport]    Script Date: 12/16/2013 16:50:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[loadBranchExport] 
	-- Add the parameters for the stored procedure
	@databaseName sysname,
	@payDate varchar(260)OUTPUT,
	@pathToFile varchar(260)OUTPUT
AS
BEGIN
	IF (@databaseName = 'Wichita')
	BEGIN
	SET @pathToFile = 'C:\Export\ICT_'+@payDate+'.xlsx'
	END
	
	SET IDENTITY_INSERT Tempus_Fugit.dbo.Processing ON
	
	INSERT INTO Tempus_Fugit.dbo.Processing 
	SELECT employeeNumber, PayCode, StartTime, EndTime, PayUnit, PayRate, Location, PayDate, Deductions, 
	Comments, SvcDate, CllientName, EmpName, BillHrs, BillRate, BillDate, EntrDate, EntrBy, 
	patientNumber, [Inv#], XferID, TimeCardID
	FROM OPENROWSET
	(
	 'Microsoft.ACE.OLEDB.12.0',
	 'Excel 12.0;Database=' + @pathToFile,
	 'SELECT * FROM [sheet1$]'
	)

END


Viewing all articles
Browse latest Browse all 4871

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>