日期:2014-05-17  浏览次数:20776 次

sql语句控制问题,急!
select condition,id,emp_no,Title,Date from consult where company=(select company from custom1 where name='"+lbl_nickname.Text+"') order by Date desc

sql语句如上,我想调用以上信息 '"+lbl_nickname.Text+"' 为当前客服名字, 
select company from custom1 where name='"+lbl_nickname.Text+"' 也就是调用custom1表中的当客服名字匹配的公司名字, 然后输出多个公司名字对应的数据。

表custom1 中 为  
客服1 公司1
客服1 公司2
客服1 公司3
客服2 公司1
客服2 公司2
客服2 公司3

问题来了:如果客服和公司不重复的话,也就是说1客服 对应1公司 是OK的。

报错:子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。  
 sda.Fill(ds,"Title");出错。

sql语句如何更改啊?想实现这功能

------解决方案--------------------
sql语句中的=改为in即可
------解决方案--------------------
where company in (select xxxxxxx)
------解决方案--------------------
select condition,id,emp_no,Title,Date from consult where company in (select company from custom1 where name='"+lbl_nickname.Text+"') order by Date desc
 
------解决方案--------------------
 用  in啊,因为你是结果集