34,590
社区成员
发帖
与我相关
我的任务
分享
rs.open "select zccalgs,xmbh,Zccalcondition from ##List_temp with(nolock) where cjftype='KDC' order by iorder",conn,3,2
do while not rs.eof
conn.execute "update HSW_farorder set fquantity=isnull(fquantity,0) + (select isnull(sum(" & rs!zccalgs & "),0) from v_HSW_PurPrice_l where cPcode='" & strCcode & "' and cpriceitemcode='" & rs!xmbh & "' and (" & rs!Zccalcondition & " )) where ccode='" & ccode & "'"
loop
update HSW_farorder set fquantity=isnull(fquantity,0) + (select isnull(sum(@zccalgs),0) from v_HSW_PurPrice_l where cPcode=@strCcode
and cpriceitemcode=@xmbh and (@Zccalcondition)) where ccode=@ccode
B. 使用带有参数的简单过程
下面的存储过程从四个表的联接中只返回指定的作者(提供了姓名)、出版的书籍以及出版社。该存储过程接受与传递的参数精确匹配的值。
USE pubs
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'au_info' AND type = 'P')
DROP PROCEDURE au_info
GO
USE pubs
GO
CREATE PROCEDURE au_info
@lastname varchar(40),
@firstname varchar(20)
AS
SELECT au_lname, au_fname, title, pub_name
FROM authors a INNER JOIN titleauthor ta
ON a.au_id = ta.au_id INNER JOIN titles t
ON t.title_id = ta.title_id INNER JOIN publishers p
ON t.pub_id = p.pub_id
WHERE au_fname = @firstname
AND au_lname = @lastname
GO
au_info 存储过程可以通过以下方法执行:
EXECUTE au_info 'Dull', 'Ann'
-- Or
EXECUTE au_info @lastname = 'Dull', @firstname = 'Ann'
-- Or
EXECUTE au_info @firstname = 'Ann', @lastname = 'Dull'
-- Or
EXEC au_info 'Dull', 'Ann'
-- Or
EXEC au_info @lastname = 'Dull', @firstname = 'Ann'
-- Or
EXEC au_info @firstname = 'Ann', @lastname = 'Dull'
如果该过程是批处理中的第一条语句,则可使用:
au_info 'Dull', 'Ann'
-- Or
au_info @lastname = 'Dull', @firstname = 'Ann'
-- Or
au_info @firstname = 'Ann', @lastname = 'Dull'
CREATE PROCEDURE test
@strCcode varchar(5000),
@ccode varchar(5000)
AS
DECLARE @zccalgs int
DECLARE @xmbh varchar(50)
Declare @Zccalcondition int
DECLARE Sourcedata_test INSENSITIVE CURSOR FOR
select zccalgs,xmbh,Zccalcondition from ##List_temp with(nolock) where cjftype='KDC' order by iorder
OPEN Sourcedata_test
FETCH NEXT FROM Sourcedata_test
INTO @zccalgs,@xmbh,@Zccalcondition
WHILE @@FETCH_STATUS = 0
BEGIN
update HSW_farorder set fquantity=isnull(fquantity,0) + (select isnull(sum(@zccalgs),0) from v_HSW_PurPrice_l where cPcode=@strCcode
and cpriceitemcode=@xmbh and (@Zccalcondition)) where ccode=@ccode
FETCH NEXT FROM Sourcedata_test
INTO @zccalgs,@xmbh,@Zccalcondition
END
CLOSE Sourcedata_test
DEALLOCATE Sourcedata_test
GO
conn.execute "update HSW_farorder set fquantity=isnull(fquantity,0) + (select isnull(sum(" & rs!zccalgs & "),0) from v_HSW_PurPrice_l where cPcode='" & strCcode & "' and cpriceitemcode='" & rs!xmbh & "' and (" & rs!Zccalcondition & " )) where ccode='" & ccode & "'"
loop