how to import csv to sql database where columns are in rows

Sachin D 21 Reputation points
2022-11-08T05:00:18.337+00:00

Hello,

We have a csv which has columns and values in rows, where all odd rows are columns and even rows contain values see screenshot below.

258040-image.png

we want to insert this data in a sql database table which would look something like this

258057-image.png

could you please guide in terms of what option we have to import this type of csv within Azure.

Azure SQL Database
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,530 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,625 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2022-11-09T12:57:33.873+00:00

    Hi @Sachin D ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your question here.
    The above requirement can be achieved using Mapping dataflow in azure data factory pipelines.

    Kindly follow the below steps to achieve the above mentioned requirement:

    1. Add source transformation and point your dataset to the .csv file . Preview the data . Two columns are present currently 'column_1' and 'col0'
    2. Add surrogate key transformation to create an identity column 'Id'. It will assign an unique value corresponding to each row.
    3. Add a conditional split with two Stream names 'ColumnNames' : Id%2!=0 and 'ColumnValues' . It will split the data into two parts: even rows and odd rows. Preview the data for both the conditions in data preview tab.

    258753-001.gif

    4. Add surrogate key transformation to both the branches to generate identity columns 'Id1' and 'Id2'. In the surrogate key data preview tab of below branch, click on 'Map drifted' option so that 'col0' would be included in the current schema. Add select transformation to deselect the unwanted 'col0' and 'Id' column from the first branch and 'Id' column from second branch.

    258762-002.gif

    5. Join the two streams 'select1' and 'select2' based on Id1 and Id2.
    6. Now, create new branch out of Join transformation . In both the branches, Add select transformation to remove 'Id1' and 'Id2' on the basis of which we performed the join.

    258708-003.gif
    7. Add pivot transformation in both the branches. Skip the 'group by' tab. In pivot key tab, select 'ColumnName' as the pivot key . In the Pivoted columns of first branch, use max(ColumnValues) as the expression and in second branch use max(Col0) . Click on map drifted in data preview tab of both the pivot transformations.

    258748-004.gif
    8. Use Union transformation to union the data of both the map drifted outputs.
    9. Use select transformation to sort the columns as per the need.

    258689-005.gif

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.