日期:2014-05-18  浏览次数:20429 次

存储过程问题!急!
有二个表   表info和表user   ,
在表info中设置一个字段   userlist
表user中的主键userid  
用程序在info表的userlist字段中存储多个用户ID,以1|10|3这样样式存储

我想查询一下某一用户在info表中userlist字段中中含有这个用户的记录的存储过程怎么写?谢谢!

------解决方案--------------------
有二个表 表info和表user ,
在表info中设置一个字段 userlist
表user中的主键userid
用程序在info表的userlist字段中存储多个用户ID,以1|10|3这样样式存储
我想查询一下某一用户在info表中userlist字段中中含有这个用户的记录的存储过程怎么写?谢谢!

select info.* , user.* from info,user where charindex( '| '+cast(user.userid as varchar) + '| ' , '| ' + info.userlist + '| ') > 0

------解决方案--------------------
汗。。
create proc wsp
@userid int
as
select info.* , user.* from info,user
where charindex( '| '+cast(user.@userid as varchar) + '| ' , '| ' + info.userlist + '| ') > 0

------解决方案--------------------
create procedure sp_test
@userid varchar(32)
as
begin
select info.* , [user].* from info,[user]
where charindex( '| '+ @userid + '| ' , '| ' + info.userlist + '| ') > 0
end