您好我正在制作一个墙存储过程,它将显示人员帖子的列表。这是下面的代码
ALTER PROCEDURE [dbo].[spDisplayWall] (@AccountName varchar(50))
/*****
Description: displays the users wall
*****/
AS
BEGIN
SELECT * FROM WallPosts
WHERE Posted_By = (SELECT AddedAccountName FROM Friends WHERE AccountName = @AccountName)
ORDER BY WallPosts.Date_Posted ASC
END
我想要上面的代码实现的是它将从朋友帐户名称相等的墙柱中选择所有内容。所以基本上回复所有朋友发帖。但由于我编码的方式,我只能回报一个朋友。我需要它返回所有人民的帖子。以下是它需要执行的所有内容,如果可能,我希望保持这种方式,它只需要帐户持有者的名字。
EXEC spDisplayWall 'KMV661'
这是我得到的错误:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
答案 0 :(得分:1)
使用in
代替=
:
SELECT *
FROM WallPosts
WHERE Posted_By in (SELECT AddedAccountName FROM Friends WHERE AccountName = @AccountName)
ORDER BY WallPosts.Date_Posted ASC