I have the following table which contains 5 columns for instance (The actual table consists of like 100 columns).
Table name: SuperStore (source)
Columns:
rid (PK), OrderID(nvarchar), OrderDate(date), Address(nvarchar), CustomerName(nvarchar), Category(nvarchar)
Sample data:
| rid | OrderID| OrderDate || Address| CustomerName| Category|
|1 |00100100| 12/12/2009 || 1233 | center | right |
|2 |00100111| 12/12/2009 || 1234 | center | left |
I have some tens of thousand's records in this.
I need the following format to be inserted in another table
Table name: Allrecords (destination)
Columns:
rowid(PK), rid(FK), TableName, ColumnName, ColumnValue, CreatedDate, ModifiedDate
Sample data:
| rowid| rid| TableName || ColumnName| ColumnValue | CreatedDate|ModifiedDate |
|1 |1 | SuperStore|| OrderID | 00100100 | |
|2 |1 | SuperStore|| OrderDate | 12/12/2009| |
|3 |1 | SuperStore|| Address | 1233 | |
Of course I can do this through a c# program that will read the source record and insert into allrecord, but I want to do this through stored procedures and also I have many source tables having many columns and need to insert into the allrecord table. Is there a way to identify the source table columns dynamically through a stored procedure and insert into the allrecords table?