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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-10-20 : 08:25:09
|
| Manish Batra writes "Hi, I want to update a table correspoding to another table. I have a table city in which cityid(pk) and cityname is available. another table flight in which FLightid(pk) fromCity and ToCity is available. The field fromcity and tocity displayed the list of city but I want to update the table flight in which fromcity and tocity should display the code of the city corresponding to table city. Pls help to write a query to update the table FLight.Hope to hear from you soon.ThanksWith RegardsManish Batra" |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-10-20 : 08:34:56
|
You'll need to do this in steps:--Add columns to hold the City IDsALTER TABLE Flight ADD FromCityID INTALTER TABLE Flight ADD ToCityID INTGOUPDATE Flight SET FromCityID = CityNameFROM Flight INNER JOIN CityON Flight.FromCity = City.CityNameGOUPDATE Flight SET ToCityID = CityNameFROM Flight INNER JOIN CityON Flight.ToCity = City.CityNameGO--Optionally drop the city name columnsALTER TABLE Flight DROP column FromCityALTER TABLE Flight DROP column ToCityGOOwais Make it idiot proof and someone will make a better idiot |
 |
|
|
|
|
|