I'm trying to transfer data from Excel into an SQL Server database. Each Excel file has a sheet for each month, and each of these sheets has the following structure where, for every "Production Unit", the values for the fields are stored for each day of the month. The field names are exactly the same for all.
... (Emptry/Irrelevant Rows)
Unit 1 | | 1| 2| 3| 4| 5| ...
Field1 |KG | 95.2| 254.12| 125.0| 125.0| 125.0| ...
Filed2 |CM | 95.2| 254.12| 125.0| 125.0| 125.0| ...
... (Other Fields)
... (Emptry/Irrelevant Rows)
Unit 2
Field1 |KG | 95.2| 254.12| 125.0| 125.0| 125.0| ...
Filed2 |CM | 95.2| 254.12| 125.0| 125.0| 125.0| ...
... (Other Fields)
... (Emptry/Irrelevant Rows)
Unit 3
...
There is a separate Excel file for each year. I would like to get all this data into the database in the following format:
Unit |Date |Field1 |Field2 | ...
1 |18/02/2008 | 23.5| 12.56| ...
1 |19/02/2008 | 23.5| 12.56| ...
...
3 |01/05/2012 | 23.5| 12.56| ...
...
I know how to take a specific segment of a sheet and then unpivot/pivot to rotate the data, but before that, I have 2 issues.
One is to rename the column names from simple numbers into full dates before (or after?) I unpivot them. So some way of appending the month (maybe based on a case statement using the sheet name) and the year (maybe from a variable that I could change for every Excel file).
The second is how to bring in the Unit data separately. There are quite a few calculated cells and empty/irrelevant rows between the Units. I would either need to specify the range for each, or bring in all and then eliminate the rows in between (which might have to be based on row numbers, since I'm not sure what other logic would apply to all). But then how do I label them as Units 1/2/3/etc? There are 5.
I'm not that familiar with SSIS and I feel a bit out of my depth here. Should all this be done in a stored procedure? And if so, is there even a need for SSIS? If it would be in SSIS where would the procedure reside? Or is there an easier way of doing all this?