NA-----------
Please copy and paste into the notepad for better view.
Don't make it better, still not really readable.
Please post table design as DDL, some sample data as DML statement and the expected result.
!
My Source data looks like above. Based the "NUMBEROFWAGONS" field value we get the "WAGONNUMBER" with the associated columns data name. In the above example since NUMBEROFWAGONS=1 and and "NUMBEROFAXLES"=1 the data looks above.
NUMBEROFWAGONS=1 and and "NUMBEROFAXLES"=2 the data looks below i.e.
Here we are getting the columns repeatedly with the same name. When loading into SQL table loading is failed because of the duplicate column (because of the same name. How can we handle the scenario?
Hi @SQL-6436,
Welcome to Microsoft Q&A!
For this type of problem we recommend that you post CREATE TABLE statements for your tables together with INSERT statements with sample data since your sample data is not readable enough.
According to your requirement, it is a little difficult to achieve in TSQL.
You could use UNPIVOT if you would like to convert one row of multiple columns to multiple rows in one table.
But there are many duplicated column names in your sample data which is not permitted in the table definition.
You may consider to deal with it in excel or other tool.
Best regards,
Melissa
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
13 people are following this question.