存储过程中表格名称能否通过参数传递?
目前需要个存储过程,基本思路如下:CREATE proc cbhs810
@rqa varchar(10),
@rqb varchar(10),
@djb varchar(20),
@zhb varchar(20)
as
SET NOCOUNT On
begin
declare @sql3 varchar(8000)
declare @wpbh varchar(9)
declare @ckmc varchar(6)
--创建游标
declare Ctab cursor
for
select distinct wpbh,ckmc from @djb as djb,@zhb as zhb where djb.djh=zhb.djh and djb.zfbz=0 and zhb.zfbz=0 and czlx in('领用出库','领用退库','销售出库','销售退库') and convert(char(10),rq,20) between ''+@rqa+'' and ''+@rqb+''
open Ctab
--获取第一条记录
fetch next from Ctab
into @wpbh,@ckmc
--判断是否有值被获取
if @@fetch_status=0
begin
-- print @wpbh
-- print @ckmc
--循环剩下的记录
fetch next from Ctab
into @wpbh,@ckmc
while @@fetch_status=0
begin
--print @wpbh
--print @ckmc
fetch next from Ctab
into @wpbh,@ckmc
end
end
close Ctab --关闭游标
deallocate Ctab
end
GO
以上存储过程中,游标打开的表格名称不确定,需要通过参数传递来,问题是:游标打开的表格名称能通过参数传递吗?如果能,该如何调用?我上面的调用方法sqlserver提示错误。