I am exporting an mssql query to an excel file which has the first two rows as a header. The first row (title) is one cell that spans from A1:K1. The second row (header) has 11 cells and spans from A2:K2. I would like to have an openrowset to change the title and a second openrowset to populate the excel file.
This doesn’t work:
EXEC('INSERT INTO OPENROWSET(''' + @provider + ''',''' + @ExcelString + ''',''SELECT Top 1 * FROM [Sheet1$]'')
SELECT Top 1 [Customer] FROM [ORDER SUMMERY] WHERE [Order #] = ''' + @OrderNumber + ''' AND (Status = ''C'' OR Status = ''I'')')
This is the second part and it does work:
EXEC('INSERT INTO OPENROWSET(''' + @provider + ''',''' + @ExcelString + ''',''SELECT * FROM [Sheet1$A3:K3]'')
SELECT [ITEMNUMBER],[CustomerSKU],[ITEM_DESCRIPTION],[CASEPACK],[Total Qty],[Case Price],[CASEPACK]*[Total Qty],[Total Qty]*[Case Price],[Unit Price],[PreTicketInfo],[Quote #] FROM [ORDER SUMMERY] WHERE [Order #] = ''' + @OrderNumber + ''' AND (Status = ''C'' OR Status = ''I'')')
Thanks!
Try this. Excel holds the value of merged cells in the top left of the merged cell range, so a merged spell spanning A1:K1 would be programmatically referred to as cell A1 when pulling value data