I need to update a SQL table with our current job info from an Excel sheet each time data captured from the Mfg equipment, I can do this by creating a stored procedure that I can execute using a JScript that is run by the program capturing the data and writing it to the Db.
I’m now able to query the Excel sheet fine and view the data that I need, but the formatting is a bit of a gotcha, without running queries to separate the data row by row then one update I can’t think of how to update it.
Query against sheet:
SELECT Item, L05, L08, L09, SS1, SS2, SS3
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY F8) AS rownumber, F1 AS Item, F2 AS L05, F3 AS L08, 4 AS L09, F5 AS SS1, F6 AS SS2, F7 AS SS3
FROM OpenDataSource( 'Microsoft.ACE.OLEDB.12.0',
'Data Source="C:\Job.xlsx";Extended Properties="Excel 12.0 XML;HDR=NO";')..."'Job Details$'") AS T2
Where rownumber >= 5 AND rownumber<=8
Returns:
Item L05 L08 L09 SS1 SS2 SS3
WO 806314 806334 806618 806314 805886 807031
TE TE2-05712 TE2-04481 TE2-06364 TE2-06345 TE2-06362 TE2-04420
TF TF2-10874 TF2-07754A TF2-14249 tf2-10874 TF2-12635 TF2-12468
Qty 39144 82800 127200 36348 121800 50660
Each equipment line is a column, and each data item is a row in the sheet, I need to reference the values and update to the table that looks like this:
LINE WO TE TF Qty
Line05 NULL NULL NULL NULL
Line08 NULL NULL NULL NULL
Line09 NULL NULL NULL NULL
SS1 NULL NULL NULL NULL
SS2 NULL NULL NULL NULL
SS3 NULL NULL NULL NULL
Ideally since the sheet is fixed I could reference the Excel cells individually in the update statement, but I haven’t seen a way to do that if it is possible.
@bluefeet This worked to pull the correct order of things, but all of the values were NULL, I wound up thinking outside the question a little and rather than re-arranging everything in T-SQL I created and hid a new Excel sheet in the workbook with cells linked to the original sheet in the order I need them, and then queried that instead.
Thanks for the help everyone.