alter proc sp_report2
@s1 varchar(100),
@k1 varchar(100),
@s2 varchar(100),
@k2 varchar(100),
@timestamp varchar(100)
with encryption
as
begin
declare @s varchar(3000)
select @s='select * from v_gdzc where 1=1 '
if isnull(@s1,'')='' and isnull(@s2,'')='' and isnull(@k1,'')='' and isnull(@k2,'')=''
select @s=@s+' and 时间戳=(select max(时间戳) from gdzc) and 期间=(select max(期间) from v_gdzc)'
if isnull(@k1,'')<>''
select @s=@s+' and '+@s1+' like ''%'+@k1+''''
if isnull(@k2,'')<>''
select @s=@s+' and '+@s2+' like ''%'+@k2+''''
if isnull(@timestamp,'')<>''
select @s=@s+' and 时间戳 like ''%'+@timestamp+''''
print @s
exec(@s)
end
exec sp_report2 '','','','',''
本文介绍了一个使用SQL加密存储过程实现动态SQL查询的例子。该过程通过参数动态构建查询条件,支持按不同字段进行模糊搜索,并可指定特定的时间戳进行数据检索。
5491

被折叠的 条评论
为什么被折叠?



