数据库中UPDATE的问题?

来源:百度知道 编辑:UC知道 时间:2024/06/06 23:21:37
update WeatherChinaXianJi
set PlaceId=s.PlaceId
from WeatherChinaXianJi t,PidChina s
where t.RegionName=s.PlaceName
哪个地方错了,为什么不出结果???
当PidChina表中PlaceName等于WeatherChinaXianJi表中的PlaceId时将PidChina中PlaceId付给WeatherChinaXianJi表中的PlaceId
update WeatherChinaXianJi
set PlaceId=s.PlaceId
from WeatherChinaXianJi t,PidChina s
where t.RegionName=s.PlaceName
哪个地方错了,为什么不出结果???

update WeatherChinaXianJi
set PlaceId=(select s.PlaceId
from WeatherChinaXianJi t,PidChina s
where t.RegionName=s.PlaceName)
就可以了

没有错.如果没有结果,应该是没有符合条件的记录吧

你可以先查一下是否有记录,如果没有的话就对了.
select t.*
from WeatherChinaXianJi t,PidChina s
where t.RegionName=s.PlaceName
and t.PlaceId<>s.PlaceId

update WeatherChinaXianJi
set PlaceId=s.PlaceId
from PidChina s
where RegionName=s.PlaceName

update WeatherChinaXianJi set WeatherChinaXianJi.PlaceId =PidChina.PlaceId where PidChina.PlaceName=WeatherChinaXianJi.PlaceId

你可以使用
select t.PlaceId,s.PlaceId
from WeatherChinaXianJi t,PidChina s where t.RegionName=s.PlaceName 查询下是否有结果
建议你 set t.PlaceId=s.PlaceId 这么写

这个语句好像不用from条件吧