There are 2 tables. The first has fname
(first name), lname
(last name) and the second has many columns including: salutation
(Mr, Dr etc), fname
(first name), mname
(middle name), lname
(last name), a uniqueidentifier and a date.
I wish to create a third table containing the Salutation
, fname
, mname
, lname
, uid
, added
from the information in the other 2 tables then I will drop the first table and re-create the second table removing those columns.
This is what I have:
CREATE TABLE MyTable
(
Id int IDENTITY (1, 1) PRIMARY KEY,
Salutation varchar(20) NULL DEFAULT (NULL),
Fname varchar(30) NOT NULL,
Mname varchar(30) NULL DEFAULT (NULL),
Lname varchar(30) NOT NULL,
Uid uniqueidentifier NULL DEFAULT (NULL),
Added Date NOT NULL DEFAULT (getdate())
);
INSERT INTO MyTable (Fname, LName)
SELECT Fname, Lname
FROM TABLE1
This is where I am confused:
INSERT INTO MyTable (Salutation, Fname, Mname, LName, Uid, Added)
SELECT
Salutation, Fname, Mname, LName, Uid, Added
FROM
Table2
WHERE
Fname, Lname NOT IN (SELECT Fname, Lname FROM Table1)
Can someone please correct the last INSERT
statement so that it works?
- it doesn't like
Fname, Lname
to the right of theWHERE
word - Should I insert from the second table first then from the first one?