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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 update with other records

Author  Topic 

nic
Posting Yak Master

209 Posts

Posted - 2004-01-30 : 12:53:51
Hi,
I thought this would be easy but I'm getting confused (glad it is Friday). I want to update one set of user records with another set of records. Below are my two attempts but neither works. I want user 2 to have the same email and phone values as user 1.



CREATE TABLE [dbo].[QuoteCommunications] (
[QuotePersonID] [int] NOT NULL ,
[CommType] [varchar] (10) NOT NULL ,
[CommValue] [varchar] (50) NOT NULL
)

INSERT INTO QuoteCommunications VALUES (1,'Email','test@test.com');
INSERT INTO QuoteCommunications VALUES (1,'Phone','867-5309');
INSERT INTO QuoteCommunications VALUES (2,'Email','');
INSERT INTO QuoteCommunications VALUES (2,'Phone','');


UPDATE QuoteCommunications SET
CommValue = a.CommValue
FROM
QuoteCommunications a JOIN QuoteCommunications b ON a.CommType = b.CommType
WHERE
a.QuotePersonID = 1
AND b.QuotePersonID = 2


UPDATE QuoteCommunications SET
CommValue = a.CommValue
FROM
QuoteCommunications a
WHERE
a.QuotePersonID = 1
AND QuotePersonID = 2
AND a.CommType = CommType


Thanks

Nic

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-01-30 : 13:11:27
[code]

UPDATE a
SET
CommValue = b.CommValue
FROM
QuoteCommunications a
JOIN
QuoteCommunications b ON a.CommType = b.CommType
WHERE
a.CommType = 'Email'
AND b.QuotePersonID = 1

UPDATE a
SET
CommValue = b.CommValue
FROM
QuoteCommunications a
JOIN
QuoteCommunications b ON a.CommType = b.CommType
WHERE
a.CommType = 'Phone'
AND b.QuotePersonID = 1

[/code]

Tara
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-01-30 : 13:17:43
[code]update qc1
set commvalue = qc.commvalue
from quotecommunications qc1
join quotecommunications qc on qc.commtype = qc1.commtype
where qc.quotepersonid = 1 and qc1.quotepersonid = 2[/code]
Go to Top of Page
   

- Advertisement -