用存储过程实现搜索功能,前提:未知表名,未知条件。
------解决方案--------------------
- SQL code
create proc procforsearch@tablename varchar(30),@wheresql varchar(100)asdeclare @sql varchar(max)declare @columns1 varchar(100)declare @columns2 varchar(100)declare @sql2 varchar(max)declare @sql3 varchar(max)declare @sql1 varchar(max)set @sql=''set @sql1=''declare c_cur cursorfor select name from syscolumns a where exists(select 1 from sysobjects where [email protected] and a.id=id)open c_curfetch next from c_cur into @columns1while @@fetch_status=0begin set @[email protected]+' or [email protected]+' like [email protected]+'%'' 'fetch next from c_cur into @columns1endclose c_curdeallocate c_curprint @sqlset @sql=right(@sql,len(@sql)-3)set @sql2='select * from [email protected]+' where [email protected]+''print @sql2exec (@sql2)exec procforsearch 'test1','1'