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

条件查询
SELECT   COUNT(DISTINCT   AcctId)   FROM   T_Account   WHERE   ExpireDate <GETDATE()   AND   AcctId   LIKE   ((SELECT     AcctPrefix   FROM   T_Distributor   WHERE   DistributorId=@DistributorId)+ '% ')
OR   AcctId   LIKE   ((SELECT     AcctPrefix   FROM   T_Distributor   WHERE   DistributorFlag=@DistributorId)+ '% ')

子查询返回的值多于一个。当子查询跟随在   =、!=、 <、 <=、> 、> =   之后,或子查询用作表达式时,这种情况是不允许的。

------解决方案--------------------
try

SELECT COUNT(DISTINCT AcctId) FROM T_Account WHERE ExpireDate <GETDATE()
AND AcctId LIKE ((SELECT TOP 1 AcctPrefix FROM T_Distributor WHERE DistributorId=@DistributorId)+ '% ')
OR AcctId LIKE ((SELECT TOP 1 AcctPrefix FROM T_Distributor WHERE DistributorFlag=@DistributorId)+ '% ')