May 11, 2011 at 3:42 pm
I am in the process of creating a DB in SQL Server 2008 R2 and am having a couple of problems. I have the following:
8 Total Tables as outlined below:
This issue is that I want to import from an excel document to the SEOStagingTable, and then run a saved process that will automatically add the data in the correct locations to the correct tables. Here is what I tried:
USE [SEO Keyword]
GO
----INSERT INTO KeywordTable using Select
INSERT INTO Keyword (Keyword, Searches, Results)
SELECT Keyword, Searches, Results
FROM SEOStagingTable
Go
----INSERT INTO WorldTable using Select
INSERT INTO World (Description)
SELECT World
FROM SEOStagingTable
Go
----INSERT INTO HubTable using Select
INSERT INTO Hub (Description)
SELECT Hub
FROM SEOStagingTable
Go
----INSERT INTO SubTable using Select
INSERT INTO Sub (Description)
SELECT Sub
FROM SEOStagingTable
Go
----INSERT INTO TagTable using Select
INSERT INTO Tag (Description)
SELECT Tag
FROM SEOStagingTable
Go
The problem is that I need to make sure that I do not create more than one of the same type of World, Hub, Sub, and Tag. Yet there can be multiple "Descriptions" for Tag, as there may be more than one Tag in relation to the Sub. Here is how it would be organized logically:
Hub -> Sub1 -> Tag1
Hub -> Sub1 -> Tag2
Hub -> Sub1 -> Tag3
Hub -> Sub2 -> Tag1
Hub -> Sub2 -> Tag4
Hub -> Sub2 -> Tag5
Can someone please help me with the Query code needed to update all tables from the one table as described above while keeping the following constraints.
World Table can only have one of each type of Description - there are duplicates in the SEOStagingTable
Hub Table can only have one of each type of Description per WorldID - there are duplicates in the SEOStagingTable
SubTable can only have one of each type of Description per HubID - there are duplicates in the SEOStagingTable
TagTable can only have one of each type of Description per SubID - there are duplicates in the SEOStagingTable
KeywordTable cannot have any duplicates in Keyword.
Thank you for your help on this issue.
Sincerely,
Aaron
May 11, 2011 at 5:58 pm
Aaron you want to change it a little so your lookup tables get populated by a SELECT featuring the DISTINCT clause:
----INSERT INTO WorldTable using Select
INSERT INTO World (Description)
SELECT DISTINCT World
FROM SEOStagingTable
Lowell
May 12, 2011 at 9:54 am
That worked out perfectly. Thank you for getting back to me on that one.
Sincerely,
Aaron
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply