• JG,

    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.

    IF object_id('tempdb..#Data') IS NOT NULL

    DROP TABLE #Data;

    CREATE TABLE #Data (

    TextCol nvarchar(30) NULL,

    NumCol nvarchar(50) NULL,

    NotExist_C1 int null,

    NotExist_C2 int null,

    NotExist_C3 int null,

    DateCol nvarchar(50) Null,

    Text2Col nvarchar(30) NULL

    )

    EXEC dbo.[uspImportExcelSheet]

    @ExcelFileName=N'C:\TestBook.xml',

    @WorkSheetName=N'Sheet1',

    @OutputTableName=N'#Data',

    @FirstRowIsHeader=1

    SELECT * FROM #Data

    IF object_id('tempdb..#Data') IS NOT NULL

    DROP TABLE #Data;