4

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

2 Answers 2

7
INSERT INTO tblNewCustomers (CustomerID, [Last Name], 
    [First Name], [existCustomer])
SELECT CustomerID, [Last Name], [First Name], True 
FROM tblOldCustomers
Sign up to request clarification or add additional context in comments.

2 Comments

Brilliant, thanks Smandoli. Hoped it would be simple to do, I had no idea how to structure it.
@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
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.