Import de-normalized relational data from Excel into SQL Server
        Posted  
        
            by roryf
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by roryf
        
        
        
        Published on 2009-04-17T09:28:05Z
        Indexed on 
            2010/05/08
            20:28 UTC
        
        
        Read the original article
        Hit count: 302
        
I need to import data from an Excel spreadsheet into SQL Server, but the data isn't in a relational/normalized format so the import wizard isn't going to cut it (as far as I know).
The data is in this format:
Category    SubCategory     Name        Description
Category#1  SubCategory#1   Product#1   Description#1
Category#1  SubCategory#1   Product#2   Description#2
Category#1  SubCategory#2   Product#3   Description#3
Category#1  SubCategory#2   Product#4   Description#4
Category#2  SubCategory#3   Product#5   Description#5
(apologies I'm lacking the inventiveness to come up with 'real' data at this time in the morning...)
Each row contains a unique product, but the cateogry structure is duplicated. I want to import this data into three tables:
Category
SubCategory
Product
(I know SubCategory should really be contained within Category, DB was not my design)
I need a way to import unique rows based on the Category and then SubCategory columns, and then when importing the other columns into Product, obtain a reference to the SubCategory based on name.
Short of scripting this, is there any way to do it using the import wizard or some other tool?
© Stack Overflow or respective owner