ALTER PROCEDURE [dbo].[SpFillAnswer]
@q_Id nvarchar(50)
AS
BEGIN
--SET NOCOUNT ON;
SELECT Answer, Date_Time, Name
FROM Answers, RegUsers
WHERE Answers.Q_Id = @q_Id
AND RegUsers.UserId = (SELECT Answers.User_Id FROM Answers WHERE Answers.Q_Id = @q_Id);
END
我有三个表,RegUsers
,Answers
和Questions
。
我必须从Answer
表中提取Date_Time
和Answers
,同时我必须找到发布答案的User Name
,这是要获取的来自RegUsers
表。
为此,我尝试了以下代码,该子代码正好运行1个结果。
但是当子查询产生多个结果时,它会给我一个错误:
(Select Answers.User_Id from Answers where Answers.Q_Id = @q_Id )
请帮助我,建议我另一个子查询,以获得我想要的结果。
Thanxx。
答案 0 :(得分:1)
将您的=
更改为IN
:
Select Answer, Date_Time, Name from
Answers, RegUsers
where Answers.Q_Id = @q_Id
and RegUsers.UserId IN (
Select Answers.User_Id
from Answers
where Answers.Q_Id = @q_Id );