Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Balance
Starting Member
24 Posts |
Posted - 2005-02-15 : 15:44:49
|
| I need to add records to the contacts table if an email address isn't associated with a matching account id. For example:I have the following code but it isn't working right...INSERT INTO dbo.contacts fname, lname, emailAddressSELECT DISTINCT fname, lname, emailAddress FROM ##contacts_tmp contacts_tmp INNER JOIN ##acctID_emailAddress_tmp acctID_email_tmp ON contacts_tmp.emailAddress = acctID_email_tmp.emailAddress INNER JOIN xref282Contacts ON acctID_email_tmp.account_id <> xref282Contacts.element_idTIA |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-15 : 15:48:16
|
try:INSERT INTO dbo.contacts (fname, lname, emailAddress)SELECT DISTINCT fname, lname, emailAddress FROM ##contacts_tmp contacts_tmp INNER JOIN ##acctID_emailAddress_tmp acctID_email_tmpON contacts_tmp.emailAddress = acctID_email_tmp.emailAddressLEFT JOIN xref282ContactsON acctID_email_tmp.account_id = xref282Contacts.element_idwhere xref282Contacts.element_id is nullGo with the flow & have fun! Else fight the flow |
 |
|
|
Balance
Starting Member
24 Posts |
Posted - 2005-02-15 : 16:06:11
|
| Tried it and no records are getting added to the contacts table. FWIW - If I remove the "where xref282Contacts.element_id is null" clause it adds the (same) record each time. |
 |
|
|
|
|
|