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 Query and Join

Author  Topic 

jrockfl
Posting Yak Master

223 Posts

Posted - 2007-08-13 : 22:38:00
I have two tables, I am trying to update tblP to a self joining parent/child relationship and delete tblMa all together.

tblMa
cus_no(parent) cus_no2(child)
1 2
1 3
1 4

tblP
cus_no ParentCus_No
1 null
2 1
3 1
4 1

UPDATE tblP
SET ParentCus_No = cus_no2
FROM tblPoints tblP
INNER JOIN tblMultipleAccounts tblMa
on tblP.cus_no = tblMa.cus_no

It does update some records, but do not seem correct. Is what I am trying to do possible? I have been looking at this too long.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-08-13 : 23:00:56
quote:
do not seem correct

Your update query seems fine. What do you mean do not seem correct ? What is not correct ? the update ?

quote:
I am trying to update tblP to a self joining parent/child relationship and delete tblMa all together

You will also need a DELETE query to delete tblMa
DELETE tblMa



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 2007-08-14 : 06:08:57
I spot checked some of the records and some should have had a value for ParentCus_No
but didn't. I can double check, I just wanted to make sure my query looked fine. Yes, I will need to delete the table once I know the records have been updated correctly.
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 2007-08-14 : 21:01:24
thanks for your help, it was a data issue.
Go to Top of Page
   

- Advertisement -