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 one table field from another

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2005-01-13 : 22:13:49
I have 2 tables. I need to update a field in table 1 from a field in table two. Here is the tricky part...

Table two has 3 fields UnitCode, UnitName and State
Table one has 3 fields QuestionID, OptionText and OptionOther

A concatinated state and unitname from table 2 was added to optionsText in table one. They were supposed to add UnitCode to OptionOther at the same time , but did not. How can I do this now and be accurate. Here is an example of the tables:

Table1:
USA-MA-AA-MD-103-1-IL Lexington Market / Store MD
USA-MA-AA-MD-109-1-IL Security Square Mall / Store MD
USA-MA-AA-MD-110-1-IL St. Charles Towne Center / Store MD


Table2:
33 MD, Lexington Market / Store 0
33 MD, Security Square Mall / Store 0
33 MD, St. Charles Towne Center / Store 0

tuenty
Constraint Violating Yak Guru

278 Posts

Posted - 2005-01-14 : 14:15:41
I haven't tested but I think it'll work

Update table1
Set OptionOther = UnitCode
Where exists
(
Select 1
from table2
Where optionsText=State+UnitName
)


.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.
A candle loses nothing by lighting another candle
Go to Top of Page

amachanic
SQL Server MVP

169 Posts

Posted - 2005-01-14 : 15:05:19

What do you want your tables to look like at the end of this update? And which columns are which? Can you lay out the data a bit better? I can't tell where one ends and the next begins.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-24 : 20:33:55
Duplicate:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=45089

Do not post your question more than once.


Tara
Go to Top of Page
   

- Advertisement -