Need Help with the Error 'Subquery returned more than 1 value'.

  • nitha jen (6/12/2013)


    can anyone help me? i am new to db....

    CREATE proc [dbo].[student_marks]

    @roll_no varchar(20)

    AS

    BEGIN

    CREATE TABLE #temp

    (

    semester INT,

    marks INT

    )

    INSERT INTO #temp

    (

    semester,

    marks

    )

    SELECT

    semester,

    ( SELECT SUM ( marks )/count(noof_sub)

    FROM student_details sd

    INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no

    WHERE sd.roll_no = @roll_no

    AND ri.semester = sm.sem_attended

    group by semester

    ) marks

    FROM student_details sd

    INNER JOIN student_marks sm ON sd.roll_no = sm.roll_no

    WHERE sm.roll_no=@roll_no

    group by semester

    SELECT *FROM #temp

    end

    the problem is when i execute the query it returns "subquery returned more than 1 value' error".because of that subquery contains 3 semesters and marks.when i remove the group by function in subquery it returns the same value for 3 rows.

    but i need the result like semester marks

    1 82

    2 75

    3 60

    what should i do to overcome this problem????thanks in advance :-):-)

    Hi nitha,

    Welcome to SSC......a few things:

    1. Check the link in my signature to know how to post in forums.

    2. Please don't hijack threads. Its already a 5 page thread and your question would get lost.

    3. For fast and better solutions please post a new thread.

    Please post DDL and sample data as shown in the link in my signature. Help us help you. Hope you have a good time on SSC. 🙂

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

Viewing post 46 (of 45 total)

You must be logged in to reply to this topic. Login to reply