日期:2014-05-18 浏览次数:20538 次
--> 测试数据:[tbl] go if object_id('[tbl]') is not null drop table [tbl] go create table [tbl]( [菜号] int, [菜名] varchar(5), [所需食材] varchar(3), [做法] varchar(5) ) go insert [tbl] select 1,'菜名1','A','做法1' union all select 2,'菜名2','ABD','做法2' union all select 3,'菜名3','ABC','做法3' union all select 4,'菜名4','CD','做法4' union all select 5,'菜名5','BC','做法5' go if OBJECT_ID('p_tracy')is not null drop proc p_tracy go create proc p_tracy @材料 varchar(10) as declare @str varchar(200) set @str='select * from tbl where charindex([所需食材],'+QUOTENAME(@材料,'''')+')>0' PRINT @STR exec(@str) exec p_tracy 'ABC' /* 菜号 菜名 所需食材 做法 1 菜名1 A 做法1 3 菜名3 ABC 做法3 5 菜名5 BC 做法5 */