当前位置: 代码迷 >> Sql Server >> 判断某几列里是否存在某个字符串,语句要怎么写呢
  详细解决方案

判断某几列里是否存在某个字符串,语句要怎么写呢

热度:211   发布时间:2016-04-27 19:22:02.0
判断某几列里是否存在某个字符串,语句要如何写呢?
页面已经获取session["username"],现在要找出数据表里某3列字段包含该用户名的记录,如何写呢?

比如:
字段名:id agroup bgroup cgroup

  记录: 1 a,b c b,d
  2 a b c

假设 session["username"]=d,那么我想取到第一条记录要怎么写呢?

------解决方案--------------------
SQL code
select top 1 * from tb where charindex(',[email protected]+',' , ','+agroup+',') > 0 or                             charindex(',[email protected]+',' , ','+bgroup+',') > 0 or                             charindex(',[email protected]+',' , ','+cgroup+',') > 0
------解决方案--------------------
SQL code
select top 1 *from tablewhere charindex(',d,',','+agroup+',') > 0 or charindex(',d,',','+bgroup+',') > 0or charindex(',d,',','+cgroup+',') > 0order by id
------解决方案--------------------
[email protected]
因为四楼的写法是变量赋值的
你前面加个
set @session=''d''
  相关解决方案