views:

209

answers:

2

Hi,

I'm using INSERT INTO to copy rows of data from one table to another:

INSERT INTO tblNewCustomers (CustomerID, [Last Name], [First Name])
SELECT CustomerID, [Last Name], [First Name]
FROM tblOldCustomers

How can I set one of the field values in tblNewCustomers for all of the new records that I am importing in withn this statement e.g

tblNewCustomers.existCustomer = TRUE

Thanks in advance for any help

Noel

+5  A: 
INSERT INTO tblNewCustomers (CustomerID, [Last Name], 
    [First Name], [existCustomer])
SELECT CustomerID, [Last Name], [First Name], True 
FROM tblOldCustomers
Smandoli
Brilliant, thanks Smandoli. Hoped it would be simple to do, I had no idea how to structure it.
glinch
I remember that sense of pleasant shock I learned it! :-)
Smandoli
@Daniel Dolz: Yes, you are right -- setting a default value in the table is usually the straightforward solution. But using SQL opens up many possibilities -- inserting different values, most obviously. In particular for Union queries, this SQL device "disambiguates" the table source and forces distinct rows: SELECT *, "A" AS Marker FROM tbl_a UNION SELECT *, "B" AS Marker FROM tbl_b
Smandoli
A: 

You can also ignore the field in the SQL sentence and make it have a default in true. BUT I think Smandoli solution is more accurate

Daniel Dolz