I am trying to import a data table from excel into SQL Server 2012, using VBA.
Preferably with help of a UDF.
The excel table looks something like this.
TableID 2012 2011 2010 2009
row 1 11 12 13 14
row 2 21 22 23 24
row 3 31 32 33 34
etc..
(I placed the numbers in the cells to designated their position. For example 11 = row 1, column 1)
The database table looks something like this.
Header: id | year | row1 | row2 | row3 | etc..
ExampData: TableId 2012 11 21 31 ..
ExampData: TableId 2011 12 22 32 ..
(This doesn't include the Primary Key column, which can be either a combination of id and year, or a NEWID()
)
I know how to import specific columns, for example I could run the following code:
INSERT INTO example_table (id, year, row1, row2, row3) VALUES ('001', '2012', '11', '21', '31')
This works great for individual columns, but how would I go about making it work for the entire table (multiple columns and rows).