tags:

views:

26

answers:

2

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?

A: 

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 <> ''

ctrlShiftBryan
+3  A: 

This should work:

INSERT INTO NewTable(partNumber, html) 
SELECT DISTINCT partNumber, html FROM OldTable WHERE html <> ''
LukLed