--用charindex select * from tb charindex(','+ltrim(你传近来的ID)+',' , ',' + FriendId + ',') > 0 select * from tb charindex(','+cast(你传近来的ID as varchar)+',' , ',' + FriendId + ',') > 0--用like也行. select * from tb ',' + FriendId + ',' like '%,'+ltrim(你传近来的ID)+',%' select * from tb ',' + FriendId + ',' like '%,'+cast(你传近来的ID as varchar)+',%'
from table where
少了where--用charindex select * from tb where charindex(','+ltrim(你传近来的ID)+',' , ',' + FriendId + ',') > 0 select * from tb where charindex(','+cast(你传近来的ID as varchar)+',' , ',' + FriendId + ',') > 0--用like也行. select * from tb where ',' + FriendId + ',' like '%,'+ltrim(你传近来的ID)+',%' select * from tb where ',' + FriendId + ',' like '%,'+cast(你传近来的ID as varchar)+',%'
--使用两个自身表 select b.* from tb a,tb b where a.id=2 and charindex(','+ltrim(b.id)+',',a.friendid)>0select b.* from tb a,tb b where a.id=2 and a.friendid like '%,'+ltrim(b.id)+',%'
select * from tb charindex(','+ltrim(你传近来的ID)+',' , ',' + FriendId + ',') > 0
select * from tb charindex(','+cast(你传近来的ID as varchar)+',' , ',' + FriendId + ',') > 0--用like也行.
select * from tb ',' + FriendId + ',' like '%,'+ltrim(你传近来的ID)+',%'
select * from tb ',' + FriendId + ',' like '%,'+cast(你传近来的ID as varchar)+',%'
select * from tb where charindex(','+ltrim(你传近来的ID)+',' , ',' + FriendId + ',') > 0
select * from tb where charindex(','+cast(你传近来的ID as varchar)+',' , ',' + FriendId + ',') > 0--用like也行.
select * from tb where ',' + FriendId + ',' like '%,'+ltrim(你传近来的ID)+',%'
select * from tb where ',' + FriendId + ',' like '%,'+cast(你传近来的ID as varchar)+',%'
我是根据一个用户来查询他里面的好友,比如传进来Uid是2,他里面好友“1,,3,4,5,6”我现在要查的是2这个人的所有好友信息,和你之前说的好像不是一个意思啊
如果有多表,表之间如何关联?
发帖注意事项
http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
select b.* from tb a,tb b where a.id=2 and charindex(','+ltrim(b.id)+',',a.friendid)>0select b.* from tb a,tb b where a.id=2 and a.friendid like '%,'+ltrim(b.id)+',%'