如何解析子查询返回的值超过1 [英] How to resolve subquery returned more than 1 value
问题描述
嗨
我执行查询时出错,而Subquery返回的错误值超过1。当子查询跟随=,!=,<,< =,>,> =或子查询用作表达式时不允许这样做
所以请帮帮我>
我给你下面的代码 -
我的尝试:
DECLARE @ Course85 VARCHAR(50)='';
DECLARE @ College85 VARCHAR(50)='';
DECLARE @ InspectionDate85 VARCHAR(50)='';
SET @ Course85 =(SELECT CourseName FROM mast_Course WHERE CourseId = @ inpCourseCode)
SET @ College85 =(SELECT CollegeName FROM CollegeMaster WHERE CollegeID = @inpCollegeCode)
SET @ InspectionDate85 =(SELECT CONVERT(VARCHAR(11),IESL.DateFrom,103)+'To'+ CONVERT(VARCHAR(11) ,IESL.DateTo,103)InspectionDate
来自Inspection_Details IES
INNER JOIN Insp_InspectorEmailStatusLog IESL ON IESL.InspectionId = IES.InspectionId和IESL.InspectorId = IES.InspectorID
WHERE IES.InspectionId=@inpInspectionId
和IES.InspectorID=@inpInspectorID
和IESL.Status IN('1','5'))
SELECT @ Course85 CourseName,@ College85 CollegeName,@ InspectionDate85 InspectionDate
一些SELECT语句返回多个值。最可能的罪魁祸首是以AND IESL.Status IN结尾(' 1' ,' 5')。但是,只有你可以找到流氓。
在子查询中使用top 1子句一次限制一条记录目前你的查询是这样的
SET @ Course85 =(SELECT CourseName ....)
SET @ College85 =(SELECT CollegeName FROM CollegeMaster .. ..)
SET @ InspectionDate85 =(SELECT ...)
通过在每个查询中添加前1来更改这些内容
SET @ Course85 =(SELECT Top 1 CourseName ....)
SET @ College85 =(从CollegeMaster中选择前1名CollegeName ....)
SET @ InspectionDate85 =(SELECT Top 1 ...)
Hi
I Get Error When i Execute Query and Error is Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
So Please Help me
I Give You Code Below-
What I have tried:
DECLARE @Course85 VARCHAR(50)='';
DECLARE @College85 VARCHAR(50)='';
DECLARE @InspectionDate85 VARCHAR(50)='';
SET @Course85=(SELECT CourseName FROM mast_Course WHERE CourseId=@inpCourseCode)
SET @College85=(SELECT CollegeName FROM CollegeMaster WHERE CollegeID=@inpCollegeCode)
SET @InspectionDate85 = (SELECT CONVERT(VARCHAR(11),IESL.DateFrom,103) +'To'+ CONVERT(VARCHAR(11),IESL.DateTo,103) InspectionDate
FROM Inspection_Details IES
INNER JOIN Insp_InspectorEmailStatusLog IESL ON IESL.InspectionId = IES.InspectionId AND IESL.InspectorId=IES.InspectorID
WHERE IES.InspectionId=@inpInspectionId
AND IES.InspectorID=@inpInspectorID
AND IESL.Status IN ('1','5'))
SELECT @Course85 CourseName, @College85 CollegeName,@InspectionDate85 InspectionDate
Some of your SELECT statements is returning multiple values. The most likely culprit is that one ending withAND IESL.Status IN ('1','5'). However, only you can find out the rogue one.
Use top 1 clause in your sub query to restrict one record at a time Currently your query are like this
SET @Course85=(SELECT CourseName ....) SET @College85=(SELECT CollegeName FROM CollegeMaster ....) SET @InspectionDate85 = (SELECT ...)
Change these to by adding Top 1 in each query
SET @Course85=(SELECT Top 1 CourseName ....) SET @College85=(SELECT Top 1 CollegeName FROM CollegeMaster ....) SET @InspectionDate85 = (SELECT Top 1 ...)
这篇关于如何解析子查询返回的值超过1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!