34,837
社区成员




--假设你需要的是C表的proxyname中的'一级代理商'
update A set 一级代理商ID = B.proxyID
from A,B,C where charindex('一级代理商',proxyname) > 0 and b.proxyID = c.proxyID and a.CARDNUMBER >= b.startcard and a.CARDNUMBER <= b.endcard
--假设你需要的是C表的faterid = 0
update A set 一级代理商ID = B.proxyID
from A,B,C where c.faterid = 0 and b.proxyID = c.proxyID and a.CARDNUMBER >= b.startcard and a.CARDNUMBER <= b.endcard
CREATE PROCEDURE my_proc
AS
begin
update A
set 已销售 = 0
from A,
(select min(cardnumber) min_cardnumber,max(cardnumber) max_cardnumber from B) T
where A.cardnumber >= T.min_cardnumber and A.cardnumber <= T.max_cardnumber
end
GO
exec my_proc
--以下是存储过程的写法.
CREATE PROCEDURE my_proc
@startcard varchar(20),
@endcard varchar(20)
AS
begin
update A
set 已销售 = 0
where A.cardnumber >= @startcard and A.cardnumber <= @endcard
end
GO
exec my_proc '100001','100100'
update A
set 已销售 = 0
from A,
(select min(cardnumber) min_cardnumber,max(cardnumber) max_cardnumber from B) T
where A.cardnumber >= T.min_cardnumber and A.cardnumber <= T.max_cardnumber