两表联合更新方式

 

oracle下:

update housea a set a.extendinfo=(select b.extendinfo from houseb b where a.houseid=b.houseid)

where a.isimage=1 and a.extendinfo is null and exists(select 1 from houseb b where a.houseid=b.houseid)

 

sqlserver下:

update a set a.extendinfo=b.extendinfo from housea a,houseb b where a.houseid=b.houseid

 

两者各不通用.第二种更简洁

下面是一个存储过程,为更新某条件之外的一部分数据.

alter procedure TQ_leasehouse

as

declare @code varchar(20)

declare cc cursor for select managercode from mlsheadcompany where companycode=201001472

open cc

fetch next from cc into @code while (@@FETCH_STATUS=0)

begin

declare @updnum int

select @updnum = COUNT(1) from rent_house.dbo.house_lease_sh_mls where agentcode=@code and registdate>CONVERT(datetime,GETDATE(),120)

update a set registdate=GETDATE() from (select * from (select registdate,ROW_NUMBER() over(order by registdate) rn

from rent_house.dbo.house_lease_sh_mls where agentcode=@code and registdate<CONVERT(datetime,GETDATE(),120)) b where rn<120-@updnum) a

fetch next from cc into @code

end

close cc

deallocate cc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值