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

问一存储过程解决思路

2012-02-01 
问一存储过程CREATEPROCEDURE [example1](@strvarchar(500))ASBEGINselect id from table1 where id in (@

问一存储过程
CREATE PROCEDURE [example1]
(@str varchar(500)  
)
AS

BEGIN  
select id from table1 where id in (@str)
end
go 
>>>>>>>>>>>
请问这样的写法有什么不对,为什么查询不出来,
@str 传入值是 1,4
table1 的记录是
id pstr
1 hello
2 hi
4 good
 

[解决办法]

SQL code
select id from table1 where id in (@str) 改为:select id from table1 where charindex(','+id+',' , ','+@str+',')>0 

热点排行
Bad Request.