表A:字段有key,A1,A2
表B:字段有key,B1
表C:字段有Key,C1Key把三张表联系起来了,每张表的Key值相等
求个存储过程,功能如下1.选择表A中,A1列中所有A1=max(A1)的列,假设有X条记录
2.在表B中,插入B1=1000/X
3.在表C中,更新C1=1
表B:字段有key,B1
表C:字段有Key,C1Key把三张表联系起来了,每张表的Key值相等
求个存储过程,功能如下1.选择表A中,A1列中所有A1=max(A1)的列,假设有X条记录
2.在表B中,插入B1=1000/X
3.在表C中,更新C1=1
declare @x int, @y int
select @y=max(A1) from 表A
select @x=count(*) from 表A
where A1=@y
update 表B set B1=1000/@x where key in (select key from 表A where A1=@y)
update 表C set C1=1 where key in (select key from 表A where A1=@y)
2.在表B中,插入B1=1000/X
3.在表C中,更新C1=1在第2步中,是不无法由update做到,第2步是由一个存储过程做的,即
update 表B set B1=1000/@x where key in (select key from 表A where A1=@y)
是由一个存储过程假设名为 updateproc完成update proc
@B1valued type
@key key这样就无法用update语句来完成啊就是想知道如何在一个存储过程当中,当按索出多个记录时,怎么对记录当中每一条值调用相应的存储过程
update 表B set B1=1000/@x where key in (select key from 表A where A1=@y)
是由一个存储过程假设名为 updateproc完成就要做到:
update 表B set B1=1000/@x where key in (select key from 表A where A1=(select max(A1) from 表A))
@x int,
@y int
as
update 表B set B1=1000/@x where key in (select key from 表A where A1=@y)
update 表C set C1=1 where key in (select key from 表A where A1=@y)
但是这个updateproc是别人已经定义好了,一次只能更新一条记录,我无法修改,你
这咱方法无法搞定啊其实这个问题的实质就是要求对一个select的结果每一条值调用一次某个存储过程
我是新手,不知道有没有方法对一个select的结果进一次for循环,这样就可以解决这
个问题了
USE pubs
GO
DECLARE authors_cursor CURSOR FOR
SELECT au_lname FROM authors
WHERE au_lname LIKE "B%"
ORDER BY au_lnameOPEN authors_cursor-- Perform the first fetch.
FETCH NEXT FROM authors_cursor-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM authors_cursor
ENDCLOSE authors_cursor
DEALLOCATE authors_cursor
GO