首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

大家帮小弟我看看这个存储过程

2012-01-11 
大家帮我看看这个存储过程!CreatePROCEDURE[dbo].[Demo1]@f1varchar(50)ASBEGINselect*fromtable1wheref1l

大家帮我看看这个存储过程!
Create   PROCEDURE   [dbo].[Demo1]
        @f1   varchar(50)
AS
BEGIN
select   *   from   table1   where   f1   like   '%@f1% '
END

执行这段代码后会建立一个存储过程。我就在查询分析器里执行该过程。然后设置参数值,可是查寻不出来任何数据(比如我给值 "1 "),但是我的记录里f1字段下绝对有值是包含 "1 "的!为什么呢?

[解决办法]
--变量要在串外面

select * from table1 where f1 like '% ' + @f1 + '% '
[解决办法]
---变量不能这么写
--方法1
select * from table1 where f1 like '% '+@f1+ '% '
--方法2
select * from table1 where charindex(@f1,f1)> 0
--方法3
select * from table1 where patindex( '% '+@f1+ '% ',f1)> 0
[解决办法]
declare @f1 sysname
set @f1 = 'sysobjects '
select * from sysobjects where name like '% ' + @f1 + '% '

热点排行