最最简单的存储过程,不会搞,-----带两个参数的删除语句
STR1= "DELETE FROM "& BBB & "_GZSPDZ WHERE exists " & _
"(select f_qlhl from rhz2 where f_lsdbm=f_qlhl and f_cd < ' "& qq & " ') "
1.上述语句中 BBB 与 qq 均为变量本来是在VB程序中直接执行的,但现在想把它
转为存储过程,如何写?
2.转为存储过程后,VB如何调用?
------解决方案--------------------create procedure sp_test(@tname varchar(40),@qq varchar(40))
as
begin
exec( 'delece from '+@tname+ '_GZSPDZ WHERE exists (select f_qlhl from rhz2 where f_lsdbm=f_qlhl and f_cd < ' ' '+@qq+ ' ' ') ')
end
------解决方案--------------------少了括號
Create Procedure SP_DELETE
(@BBB Varchar(50),
@qq Varchar(50))
As
Begin
Declare @S Varchar(8000)
Select @S = 'DELETE FROM ' + @BBB + '_GZSPDZ WHERE exists (select f_qlhl from rhz2 where f_lsdbm=f_qlhl and f_cd < ' ' ' + @qq + ' ' ') '
EXEC(@S)
End
GO
--調用
EXEC SP_DELETE 'AAA ', 'BBBB '
------解决方案--------------------create proc test(@bbb varchar(20),@qq varchar(20))
as
declare @str1 varchar(8000)
select @str1= 'DELETE FROM '+ @BBB + '_GZSPDZ WHERE exists (select f_qlhl from rhz2 where f_lsdbm=f_qlhl and f_cd < ' ' '+@qq+ ' ' ') '
exec(@str1)