日期:2014-05-18 浏览次数:20665 次
if object_id('A') is not null drop table A
go
create table A(
GNO nvarchar(20) not null,
POINT float,
[MIN] int,
[MAX] int
)
go
if object_id('B') is not null drop table B
go
create table B(
SNO nvarchar(20) not null,
CNO nvarchar(20) not null,
TNO nvarchar(20) not null,
GRADE int,
POINT float
)
go
alter table B add constraint [PK_B] primary key clustered(SNO,CNO,TNO) on [PRIMARY]
go
insert into A
select 'g1',20,1,5
union all select 'g2',30,6,10
go
insert into B
select 's1','c1','t1',2,0
union all select 's2','c2','t2',7,0
go
if objectproperty(object_id('TestProc'),'IsProcedure')=1
drop procedure TestProc
go
create procedure TestProc
as
update B
set B.POINT=A.POINT
from A
where B.GRADE between A.[MIN] and A.[MAX]
go
exec TestProc
select * from A
select * from B
drop proc TestProc
drop table A
drop table B