有两张表 绩点(GNO,POINT,MIN,MAX) 主键为GNO
成绩(SNO,CNO,TNO,GRADE,POINT)主键为(SNO.CNO.TNO)
现需要将B表中的每个GRADE分别和A表中的MIN和MAX相比较,若满足GRADE>=MIN && GRADE<=MAX 则更新B.POINT = A.POINT
我对存储过程不是很清楚,哪位高手能写一个完整的学习学习!!!
------解决方案--------------------
- SQL code
if object_id('A') is not null drop table Agocreate table A(GNO nvarchar(20) not null,POINT float,[MIN] int,[MAX] int)goif object_id('B') is not null drop table Bgocreate table B(SNO nvarchar(20) not null,CNO nvarchar(20) not null,TNO nvarchar(20) not null,GRADE int,POINT float)goalter table B add constraint [PK_B] primary key clustered(SNO,CNO,TNO) on [PRIMARY]goinsert into A select 'g1',20,1,5union all select 'g2',30,6,10goinsert into B select 's1','c1','t1',2,0union all select 's2','c2','t2',7,0goif objectproperty(object_id('TestProc'),'IsProcedure')=1drop procedure TestProcgocreate procedure TestProcasupdate Bset B.POINT=A.POINTfrom Awhere B.GRADE between A.[MIN] and A.[MAX]goexec TestProcselect * from Aselect * from Bdrop proc TestProcdrop table Adrop table B