Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2014
    Posts
    2

    Unanswered: Stored Procedures subquery returns more than one value

    I'm very new to SQL (using 2012), only been working with it for a couple of weeks. I'm trying to create some stored procedures that calculate stats needed for item response theory and test scoring (things like reliability, correlation, etc.). I'm writing a procedure that's aimed at splitting a test in half (first half of the items and second half of the items) and calculating each individual (TestID) score for each half. I can insert the first half of the test, but end up getting an error stating that the subquery returned more than one value. I know it's being caused by the group by clause, but if I remove it I end up with a total count of the items answered correctly, but it's necessary for me to link it batch to the TestID (so each row should have a BatchID [same for all at the moment], a unique TestId, a corresponding FirstHalfScore and a corresponding SecondHalfScore for each testID). Any help would be much appreciated. Thank you!!!!


    Insert into SplitHalfTestScores (BatchId, TestID, FirstHalfScore)
    (Select distinct 10001 as BatchId, irt.TestID, count(*) as FirstHalfScore
    From irt_TestItems irt where batchID=10001 and ItemId <=40 and TestId = irt.TestId and AnsweredCorrectly = 1 group by TestId)

    Update SplitHalfTestScores
    Set SecondHalfScore = (Select count(*)
    From irt_TestItems irt where BatchId = 10001 and TestId = irt.TestId and irt.ItemId > 40 and AnsweredCorrectly = 1
    group by TestId)

  2. #2
    Join Date
    Nov 2014
    Posts
    2

    Nevermind...

    I got it.

    Insert into SplitHalfTestScores (BatchId, TestID, FirstHalfScore)
    (Select distinct 10001 as BatchId, irt.TestID, count(*) as FirstHalfScore
    From irt_TestItems irt where batchID=10001 and ItemId <=40 and TestId = irt.TestId and AnsweredCorrectly = 1 group by TestId)

    Update SplitHalfTestScores
    Set SecondHalfScore = (Select count(*)
    From irt_TestItems irt where BatchId = 10001 and irt.ItemId > 40 and irt.TestId = SplitHalfTestScores.TestID and AnsweredCorrectly = 1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •