October 24, 2018 at 8:29 am
I'm trying to update a set of rows and exclude several, but my EXCEPT operator is erroring:
UPDATE a SET
a.Address1 = b.Address1, a.Address2 = b.Address2, a.city = b.city, a.stateAbbrev = b.stateAbbrev, a.phoneNumber = b.phoneNumber,
a.email = b.email, a.workPhone = b.workPhone, a.postalCode = b.postalCode, a.faxNumber = b.fax
FROM GCDF_DB..PeopleContactInfo a JOIN BCC_DB..PeopleNotes b ON a.peopleid = b.peopleid
EXCEPT
SELECT b.peopleid
FROM BCC_DB..PeopleNotes b
WHERE b.peopleid in (16189,16535, 17521, 16434, 8859)
SELECT @@ROWCOUNT
October 24, 2018 at 8:33 am
The error message is helpful in cases like this. In its absence, I'll guess that it's because the two result sets don't have the same number of columns.
John
October 24, 2018 at 8:34 am
briancampbellmcad - Wednesday, October 24, 2018 8:29 AMI'm trying to update a set of rows and exclude several, but my EXCEPT operator is erroring:
UPDATE a SET
a.Address1 = b.Address1, a.Address2 = b.Address2, a.city = b.city, a.stateAbbrev = b.stateAbbrev, a.phoneNumber = b.phoneNumber,
a.email = b.email, a.workPhone = b.workPhone, a.postalCode = b.postalCode, a.faxNumber = b.fax
FROM GCDF_DB..PeopleContactInfo a JOIN BCC_DB..PeopleNotes b ON a.peopleid = b.peopleid
EXCEPT
SELECT b.peopleid
FROM BCC_DB..PeopleNotes b
WHERE b.peopleid in (16189,16535, 17521, 16434, 8859)
SELECT @@ROWCOUNT
Except expects both queries to have the same number of columns and datatypes.
October 24, 2018 at 8:38 am
Try this:
update [a]
set [a].[Address1] = .[Address1]
, [a].[Address2] = .[Address2]
, [a].[city] = .[city]
, [a].[stateAbbrev] = .[stateAbbrev]
, [a].[phoneNumber] = .[phoneNumber]
, [a]. = .
, [a].[workPhone] = .[workPhone]
, [a].[postalCode] = .[postalCode]
, [a].[faxNumber] = .[fax]
from
[GCDF_DB].[dbo].[PeopleContactInfo] as [a]
join [BCC_DB].[dbo].[PeopleNotes] as
on [a].[peopleid] = .[peopleid]
where
.[peopleid] in (16189,16535, 17521, 16434, 8859);
October 24, 2018 at 8:41 am
Lynn Pettis - Wednesday, October 24, 2018 8:38 AMTry this:
update [a]
set [a].[Address1] = .[Address1]
, [a].[Address2] = .[Address2]
, [a].[city] = .[city]
, [a].[stateAbbrev] = .[stateAbbrev]
, [a].[phoneNumber] = .[phoneNumber]
, [a]. = .
, [a].[workPhone] = .[workPhone]
, [a].[postalCode] = .[postalCode]
, [a].[faxNumber] = .[fax]
from
[GCDF_DB].[dbo].[PeopleContactInfo] as [a]
join [BCC_DB].[dbo].[PeopleNotes] as
on [a].[peopleid] = .[peopleid]
where
.[peopleid] in (16189,16535, 17521, 16434, 8859);
Oops. Change the IN to NOT IN.
October 24, 2018 at 8:44 am
Thanks! works
October 24, 2018 at 4:19 pm
UPDATE a SET
a.Address1 = b.Address1
, a.Address2 = b.Address2
, a.city = b.city
, a.stateAbbrev = b.stateAbbrev
, a.phoneNumber = b.phoneNumber
, a.email = b.email
, a.workPhone = b.workPhone
, a.postalCode = b.postalCode
, a.faxNumber = b.fax
FROM GCDF_DB..PeopleContactInfo a
JOIN BCC_DB..PeopleNotes b ON a.peopleid = b.peopleid
WHERE b.peopleid NOT IN (16189,16535, 17521, 16434, 8859);
October 25, 2018 at 4:14 pm
MERGE INTO people_Contact_Info AS A
WHEN MATCHED
USING (SELECT people_id,
address1, address2,
city_name, state_code,postal_code,
email_address,
something_phone_nbr,work_phone_nbr, fax_phone_nbr
FROM People_Notes
WHERE B.people_id NOT IN (16189,16535, 17521, 16434, 8859)
ON A.people_id = B.people_id
THEN UPDATE
SET A.address1 = B.address1,
A.address2= B.address2,
A.city_name= B.city_name,
A.state_code= B.state_code,
A.something_phone_nbr =B.something_phone_nbr,
A.email_address= B.email_address,
A.work_phone_nbr= B.work_phone_nbr,
A.postal_code= B.postal_code,
A.fax_phone_nbr= B.fax_phone_nbr;
[/code]
Please post DDL and follow ANSI/ISO standards when asking for help.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply