我在 SQL Server 2005 上,我收到一个我很确定不应该收到的错误。
Msg 512, Level 16, State 1, Procedure spGetSavedSearchesByAdminUser, Line 8 Subquery
returned more than 1 value. This is not permitted when the subquery
follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
我正在关注 此MSDN 链接上的示例#B。
我存储的过程代码如下。如果您要求,我可以为这篇文章简化它:
ALTER PROCEDURE [dbo].[spGetSavedSearchesByAdminUser]
@strUserName varchar(50)
,@bitQuickSearch bit = 0
AS
BEGIN
SELECT [intSearchID] ,strSearchTypeCode ,[strSearchName]
FROM [tblAdminSearches]
WHERE
strUserName = @strUserName
AND
strSearchTypeCode
IN (
CASE @bitQuickSearch
WHEN 1 THEN 'Quick'
ELSE (SELECT strSearchTypeCode FROM tblAdvanceSearchTypes)
END
)
ORDER BY strSearchName
END
我已经检查了子查询的结果集和与子查询结果进行比较的 strSearchTypeCode 之间没有数据类型不匹配。
我看不出为什么这不起作用。如果您有任何线索,请告诉我。