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
 SQL Server Development (2000)
 Update table columns with values from Temp Table

Author  Topic 

tchinedu
Yak Posting Veteran

71 Posts

Posted - 2005-11-17 : 11:19:34
Please help guys,

I'm basically trying to update one table from values in another table
I need to create a procedure that goes thru and updates my tables based on the new values I have in a temp table...

this is just to give an idea of what I'm trying to do

Create Procedure UpdateGroupingMap
as
update GroupingMap
set GroupingMap.GroupNumber = TempTable.GroupNumber
Where GroupingMap.Gr_ID = TempTable.Gr_ID
and GroupingMap.p_ID = TempTable.p_ID

Please help

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-17 : 11:23:20
quote:
Originally posted by tchinedu

Please help guys,



ues that leaves you out Tara

quote:

I'm basically trying to update one table from values in another table
I need to create a procedure that goes thru and updates my tables based on the new values I have in a temp table...



OK, should be simple enough...follow the hint link in my sig and post some info for us



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

tchinedu
Yak Posting Veteran

71 Posts

Posted - 2005-11-17 : 11:44:36
basically I have a temp table with columns: - pr_ID and gr_ID and gr_num. pr_id and gr_id are the combo key. all cols are int type

example data
pr_ID gr_ID gr_num
1 --- 345 --- 1
2 --- 654 --- 3
3 --- 567 --- 1
4 --- 345 --- 2
5 --- 123 --- 1
6 --- 987 --- 2
etc

and a destination table with same columns, I want to update the destination table with values from tempTable. my application has done some calculations and changed the temp table groupNumber values, and I want to update all groupNumber's in the destination table with values from the temp table.
Go to Top of Page

tchinedu
Yak Posting Veteran

71 Posts

Posted - 2005-11-17 : 11:55:18
Would this do it...

Create Procedure UpdateGroupingMap
as
update GroupingMap
set GroupNumber = (select GroupNumber from GroupingTempTable s,
GroupingMap c
where c.gr_ID = s.gr_ID and
c.p_ID = s.p_ID)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-17 : 23:38:38
update c
set c.GroupNumber = s.GroupNumber
from GroupingMap c inner join GroupingTempTable s,
on c.gr_ID = s.gr_ID where c.p_ID = s.p_ID


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tchinedu
Yak Posting Veteran

71 Posts

Posted - 2005-11-18 : 16:44:18
Thank you so much...
Go to Top of Page
   

- Advertisement -