Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Combine Results?

Author  Topic 

dcummiskey
Starting Member

26 Posts

Posted - 2008-08-04 : 16:20:21
Hello -
I have a stored procedure that returns three result sets. Is there a way to return one result set with all of the data. Basically, I would need one row per student (found in section 1) with a column for every test (found in section 2) and the results for each test for that specific student (found in section 3)?? Not sure if this is possible but figured I would post and see. Thanks for your time.


--Section 1 This section gets the list of students who were enrolled during the date range given.

SELECT DISTINCT
S.StudentDimKey, S.StudentID, S.FirstName, S.LastName, SD.SchoolID, SD.NCSSchoolName
FROM
CLT_StudentDim S
INNER JOIN CLT_StudentAssessmentRawFact SA ON S.StudentDimKey = SA.StudentDimKey
INNER JOIN CLT_AssessmentDim A ON SA.AssessmentDimKey = A.AssessmentDimKey
INNER JOIN CLT_SchoolDim SD ON S.SchoolID = SD.SchoolID
WHERE
S.DistrictID = @DistrictID
AND SA.EvaluationDate BETWEEN @StartDate AND @EndDate
AND A.ProductKey = @ProductKey

--Section 2 This section gets the list of tests given between the start and end dates.

SELECT DISTINCT
A.AssessmentDimKey, A.AssessmentName, A.AssessmentTypeName
FROM
CLT_StudentAssessmentRawFact SA
INNER JOIN CLT_AssessmentDim A ON SA.AssessmentDimKey = A.AssessmentDimKey
WHERE
SA.EvaluationDate BETWEEN @StartDate AND @EndDate
AND A.ProductKey = @ProductKey

-- Section 3 This section gets the studentdimkey, assessmentdimkey, and score for the test for
-- each test taken during the time frame

SELECT DISTINCT
SA.AssessmentDimKey, SA.StudentDimKey, SA.Score, A.NumOfQuestions, A.Book, A.Step
FROM
CLT_StudentAssessmentRawFact SA
INNER JOIN CLT_AssessmentDim A ON SA.AssessmentDimKey = A.AssessmentDimKey
WHERE
SA.EvaluationDate BETWEEN @StartDate AND @EndDate
AND A.ProductKey = @ProductKey

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-08-04 : 16:25:28
Please provide sample data and desired results.
Go to Top of Page

dcummiskey
Starting Member

26 Posts

Posted - 2008-08-04 : 17:04:21
SECTION 1 RESULTS

StudentDimKey StudentID FirstName LastName
------------- --------------------------------------------------
26270 101010 Bo Bo
26275 101011 BE BE
26282 101012 CECE CE
26290 101013 FRO BLOW
26310 101014 FISH HEK


SECTION 2 RESULTS -- # OF TESTS RETURNED CAN VARY
AssessmentDimKey AssessmentName AssessmentTypeName
---------------- --------------- --------------------
6172 Spelling Posttest 1 Content Mastery
6080 Spelling Posttest 2 Content Mastery
6126 Final Consonant +<i> le</i> and Vwl digraphs Content Mastery
6567 Passage Fluency 1 Interactive Text
6083 Subject or Direct Object Content Mastery
6060 TOSWRF-A Placement Test
6160 Vocabulary Summative Test
6103 Grammar and Usage Content Mastery
6152 Synonyms Content Mastery
6564 Word Fluency 1 - Unit Vocabulary Interactive Text
6169 Word Fluency 3 - Unit Vocabulary Interactive Text
6129 Diphthong Syllables Content Mastery
6106 Suffixes Content Mastery


SECTION 3 RESULTS

AssessmentDimKey StudentDimKey Score
---------------- ------------- ---------------------------------------
6060 26270 100
6060 26275 85
6060 26282 200
6060 26290 10
6060 26310 100
6060 35730 30
6061 26270 100
6061 26275 85
6061 26282 200
6061 26290 10
6061 26310 100
6061 35730 30
6152 26270 100
6152 26275 85
6152 26282 200
6152 26290 10
6152 26310 100
6152 35730 30


--FINAL RESULTS
StudentDimKey StudentID FirstName LastName Spelling Posttest 1 Spelling Posttest 2 Final Consonant Passage Fluency 1 Subject or Direct Object TOSWRF-A Vocabulary Grammar and Usage Synonyms Word Fluency 1 Word Fluency 3 Diphthong Syllables Suffixes
26275 101011 BE BE 85 85 null null null 21 null null null null null null null null
26282 101012 CECE CE 200 200 null null null 21 null null null null null null null null
26290 101013 FRO BLOW 10 10 null null null 21 null null null null null null null null
26310 101014 FISH HEK 100 100 null null null 21 null null null null null null null null


Go to Top of Page
   

- Advertisement -