Reputation: 103717
I have 2 tables:
NewTable (partNumber, html)
OldTable(partNumer, html)
The old table has duplicate data i.e. rows with the same partNumber and html.
NewTable is empty.
I want to take the rows from 'OldTable' and insert them into NewTable.
The only condition that I get any row from 'OldTable' where the html column is not an empty string, so:
SELECT TOP 1 FROM OldTable WHERE html <> ''
What would the update look like?
Upvotes: 1
Views: 78
Reputation: 31892
This should work:
INSERT INTO NewTable(partNumber, html)
SELECT DISTINCT partNumber, html FROM OldTable WHERE html <> ''
Upvotes: 3
Reputation: 27760
Put a unique index on the NewTable including partNumber and html then turn on Ignore dups.
Then you can simply...
INSERT NewTable(partNumber, html) SELECT OldTable partNumer, html WHERE html <> ''
Upvotes: 0