BTW, does SQL 2005 has a setting that allows you to put a key field as an increment like Access does? If it does, then I would not have to worry about this incremented field.
That is an IDENTITY column in MS SQL Server.
Code:
CREATE TABLE MyProducts (product_id INT IDENTITY)
See Books Online topic CREATE TABLE for more information.
In addition, table1 has a field in that requires an incremental number (Product.id).
Yes, you lost me on this. Possibly, you meant that table2 requires the Product.id . I say this because I think table2 is the target table which will have all of the correct data when we are finished; therefore, we dont care what table1 requires.
Furthermore, if the Product.id has already been established then the import must take the existing value from table1 and store it in table2. Therefore there is no need to generate an incrementing number.
Possibly you mistyped these.
Code:
SELECT * FROM TABLE1 [COLOR=red]WHERE[/color] TABLE1.ID NOT IN [COLOR=red]([/color] SELECT ID FROM MyViewOfDuplicates [COLOR=red])[/color]
Code:
SELECT *
FROM TABLE1
WHERE TABLE1.ID
NOT IN ( select [COLOR=green]table2.[/color]ID
FROM table2
INNER JOIN table1 ON table2.ID = table1.ID )
That seems like it would find the rows in table1 which are not in table2.
Assuming we have a SELECT statement that yields exactly the rows we wish to INSERT into table2, the other issue is the the blank values. This can be handled with expressions that calculate the desired value.
If the blank values are NULL values then the ISNULL(column_name, substitute_value) function can be used.
Code:
SELECT ISNULL(colA, 'None'),
ISNULL(colB, 0),
ISNULL(colC, colA + colD)
FROM MyTable
Here I am substituting the value None in a VARCHAR column and the value 0 in a number column.
If the desired values should be calculated from the values in other columns then the substitute_value would be an expression.
If the blank values are empty strings or actual space characters, then a CASE expression can be used.
Code:
SELECT CASE
WHEN colA = '' THEN 'None'
WHEN colA = ' ' THEN 'None'
ELSE colA
END
FROM MyTable