Copy codeThe Code is as follows:
IF Exists (Select 1 From sysobjects Where Name = 'SP _ search' And xType = 'P ')
Drop Procedure sp_search
Go
/*
General Stored Procedure of fuzzy query
Create by sxm, date 2009-7-14
Parameters:
@ Table_name 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 =''
-- Query the column name in the table
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
-- Combined Query Conditions
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