这样的存储过程怎么写?在线等!来者有分!!1
如题,数据库中有很多表,每个表都有一个字段name,请问我想对这些表应用一个存储过程,
查询条件是name字段中含有类似于varchar变量str的字段。
"select * from " + tablename + " where name LIKE %str%";
在存储过程中需要定义两个变量,请问高手怎么写?马上给分!
问题点数:20、回复次数:5Top
1 楼zlp321002(Life Is Good,Let's Shine)回复于 2006-05-01 16:53:29 得分 0
exec('select * from '+tablename+' where name like '%str%' ')Top
2 楼huntbookren()回复于 2006-05-01 17:20:14 得分 0
CREATE PROCEDURE Find_book
@table_name varchar(20),@strsql varchar(200)
AS
exec('select * from '+ @table_name + ' where leibie = '+ @strsql )
GO
EXECUTE Find_book @table_name = 'vb', @strsql = 'vb教程'
这样写为何有错误??????????????
Top
3 楼zlp321002(Life Is Good,Let's Shine)回复于 2006-05-02 08:34:14 得分 0
--报告什么错误??Top
4 楼wangtiecheng(不知不为过,不学就是错!)回复于 2006-05-02 08:36:41 得分 0
exec('select * from '+ @table_name + ' where leibie = '+ @strsql )
-->
exec('select * from '+ @table_name + ' where leibie = '''+ @strsql + '''' )Top
5 楼xeqtr1982(Visual C# .NET)回复于 2006-05-02 08:51:29 得分 0
exec('select * from '+@tablename+' where name like ''%'+@str+'%''')Top




