In your case, it's better to pre-create your table with all necessary columns, allow null for those columns that do not exist in the worksheet. Then call the SP to import data to the table. The columns that do not exist in the worksheet will have NULL value, e.g.

Yes. I have a table already created. I had to look again to be sure of the fields. I was mistaken from before. The table has 1 NOT NULL field - it's the Identity column. You gave code to ignore that column in the -- Physical Table section - and that works perfectly.

The next two columns are not in the xml spreadsheet. The xml spreadsheet's 1st column is the pre-created table's 4th column.

as in:

identity column, not exist in ss, not exist in ss, text4 col.

When I run the SP, the identity column increments as it should, the two not exist columns contain NULL, as expected, and the text4 col plus the remaining 117 columns have data from the xml spreadsheet.

What I'd like to have is the ability to pass in the data for the two 'not exist' columns so that all the data goes into the 'pre-created' table.

I have this so far...EXEC dbo.uspImportExcelSheet@ExcelFileName=N'C:\TestTable.xml',@WorkSheetName=N'Sheet1',@OutputTableName=N'Staging.Sales',@FirstRowIsHeader=1,@ClientAccountNum=N'R555',@ClientAccountID=N'232',@Debug=0

In the SP above @Debug tinyint=0, I have...@ClientAccountNum nvarchar(4)=N'',@ClientAccountID nvarchar(255),

In the SELECT after BEGIN TRY, I have...SELECT @OutputTableName=ISNULL(LTRIM(RTRIM(@OutputTableName)),N''), @WorkSheetName=ISNULL(LTRIM(RTRIM(@WorkSheetName)),N''), @ExcelFileName=ISNULL(LTRIM(RTRIM(@ExcelFileName)),N''),@ClientAccountNum=ISNULL(LTRIM(RTRIM(@ClientAccountNum)),N''), @ClientAccountID=ISNULL(LTRIM(RTRIM(@ClientAccountID)),N''), @FirstRowIsHeader=ISNULL(@FirstRowIsHeader,0), @RowsToCheckDataType=ISNULL(@RowsToCheckDataType,0), @RowsToImport=ISNULL(@RowsToImport,0); -- Check valid excel file name is given

And because these two fields are needed, I have added the appropriate RAISERROR code.

What I need help on, is where do I insert these variables so that they will 'insert' into the 'pre-create' table in the appropriate columns.

The SP is a generic tool to import xml spreadsheet. After data is imported, you can apply any logic and processing to the data within your table. As that said, if you need any special handling of the data, it is better to do it after the data is imported into the table.

In your scenario, after the data is imported, you can update the table like:

I receive XML Spreadsheet 2003 with xls extension and the WorkSheetName is a Space.This spreadsheet is generated by another system, which is not under the control of my business user. Is there a way of just reading the first sheet, which in my case is the only sheet in the workbook without the WorksheetName ?

I recently ran into a file exported by a company in this Excel 2003 XML format, although they were named as .xls files. I don't know about JET, but I was unable to read these files with the latest ACE.OLEDB drivers. I've used ACE with a number of XLS and XLSX files, but it refused to read this older, plain XML format. (If anyone uses them, I'm talking about IHS production workbook exports... so if you're in the Petro industry, you might be familiar with these)

Anyway, so I modified this procedure to work with SQL 2008 R2... it appears that it's use of #temp tables isn't possible with the scope of dynamically executed SQL. So all I did was change that to use a global temp table. It also didn't handle strange column names, so I changed it to [box in] those as well.... so far, so good!

Attached is my updated version of the sproc, if you have use for it, enjoy!