首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

最最简单的存储过程,不会搞,带两个参数的删除语句解决思路

2012-01-08 
最最简单的存储过程,不会搞,-----带两个参数的删除语句STR1 DELETEFROM&BBB& _GZSPDZWHEREexists &_

最最简单的存储过程,不会搞,-----带两个参数的删除语句
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
(@BBBVarchar(50),
@qqVarchar(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)

热点排行