模糊查询的通用存储过程
时间:2024-01-23 06:49:12
IF Exists(Select 1 From sysobjects Where Name='sp_search' And xType='P')
Drop Procedure sp_search
go
/*
模糊查询的通用存储过程
create by sxm,date 2009-7-14
参数:
@table_name 表名
@condition 条件
*/
create proc sp_search(@table_name varchar(200),@condition varchar(100))
with encryption
as
begin
declare @strsql varchar(8000)
declare @col_name varchar(100)
declare @str_cols varchar(8000)
set @str_cols=''
--查询表中的列名
declare cur_1 cursor for select column_name from information_schema.columns where table_name=@table_name
open cur_1
fetch cur_1 into @col_name
while @@fetch_status=0
begin
--组合查询条件
set @str_cols=@str_cols + @col_name+' like ''%' + @condition+ '%''' + ' or '
fetch cur_1 into @col_name
end --while
close cur_1
deallocate cur_1
set @str_cols=left(@str_cols,len(@str_cols)-3)
--print @str_cols
set @strsql='select * from '+@table_name+' where '+ @str_cols
exec(@strsql)
end
标签:模糊查询,存储过程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
模拟下拉菜单[兼容IE系列以及火狐]
2009-12-13 10:23:00
![](https://img.aspxhome.com/file/UploadPic/200912/13/menu-37s.gif)
详解Python中映射类型的内建函数和工厂函数
2022-10-15 06:24:55
js控制文本框禁止输入特殊字符详解
2024-04-25 13:07:03
浅谈ACCESS数据库升迁SQLSERVER注意事项
2007-08-11 13:44:00
Tensorflow2.1 MNIST图像分类实现思路分析
2023-04-17 03:35:32
git本地分支和stash内容报错消失的问题
2023-10-19 01:48:47
python sklearn常用分类算法模型的调用
2021-06-18 11:42:25
如何理解及使用Python闭包
2021-12-22 23:50:59
![](https://img.aspxhome.com/file/2023/0/131300_0s.png)
Oracle 日期的一些简单使用
2009-08-05 20:42:00
js实现rem自动匹配计算font-size的示例
2023-08-22 11:02:33
JS FormData对象使用方法实例详解
2024-02-25 04:54:46
一篇文章彻底弄懂Python中的if __name__ == __main__
2023-04-27 08:42:14
Linux操作系统下MySQL数据库的使用方法
2008-12-26 09:24:00
MySQL表字段设置默认值(图文教程及注意细节)
2024-01-18 14:34:52
![](https://img.aspxhome.com/file/2023/6/126266_0s.gif)
js验证表单(form)中多选框(checkbox)值
2008-03-18 13:39:00
Python线上环境使用日志的及配置文件
2023-11-12 13:23:56
深入解析Python中的集合类型操作符
2022-06-19 01:04:33
Python实现批量压缩图片
2021-04-20 09:58:44
![](https://img.aspxhome.com/file/2023/9/109849_0s.jpg)
如何把ASP源代码编写成DLL组件
2007-10-19 13:49:00
mysql创建表设置表主键id从1开始自增的解决方案
2024-01-18 13:52:53
![](https://img.aspxhome.com/file/2023/6/67076_0s.png)