SQL数据库表中多行数据交换
SQL数据库表中多行数据互换存储过程的代码表如下:select * from tblEquipmentOrSkill where RoleID @iRo
SQL数据库表中多行数据互换
存储过程的代码
表如下:
select * from tblEquipmentOrSkill where RoleID = @iRoleID and Position = @iRepPos
select * from tblEquipmentOrSkill where RoleID = @iRoleID and Position = @iByPos
把这两条语句查询出来的数据进行交换,如何做?
初次接触存储过程,不是太熟悉,希望各位帮帮忙,谢谢! 数据库 sql 存储
[解决办法]什么叫做交换?是更新吗?
[解决办法]放到一个临时表,然后再更新
[解决办法]update tblEquipmentOrSkill set position = I2.position
from tblEquipmentOrSkill I1 inner join (
select t1.RoleID,t2.position,t1.itemID from (
select * from tblEquipmentOrSkill
where RoleID = @iRoleID and Position = @iRepPos
) t1 inner join
(
select * from tblEquipmentOrSkill where RoleID = @iRoleID and Position = @iByPos
) t2
on t1.RoleID = t2.RoleID
) I2
on I1.ItemID = I2.ItemID