all groups > sql server programming > october 2005 >
You're in the

sql server programming

group:

Combining two rows in a view


RE: Combining two rows in a view ML
10/12/2005 5:38:03 PM
sql server programming: Take a look at this example:
http://milambda.blogspot.com/2005/07/return-related-values-as-array.html


Combining two rows in a view TheCount
10/12/2005 8:29:23 PM
I have created a view for reporting. I’m basically just joining a few
tables. It is for a University so the results shows students names and
the credits they are currently taking and the school code (There is 3
Colleges under one ownership)

The problem is some students attend two colleges and appear twice,
one for each enrollment. For example

FName LName Credits SchoolCode
John Smith 12 1468
John Smith 4 1469

I need to combine these results so it would look like this

John Smith 16 1468

This is not for all students just certain ones. I would like to do
this in the view if possible. Any help is appreciated.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/Programming-Combining-rows-view-ftopict262850.html
Re: Combining two rows in a view Itzik Ben-Gan
10/13/2005 12:00:00 AM
Looks like you want to return just one of the school codes? In that case,
just group the data by student, and aggregate the measures:

SELECT StudentID, FName, LName, SUM(Credits) AS TotalCredits,
MIN(ScheelCode) AS MinSchoolCode
FROM ViewName
GROUP BY StudentID, FName, LName;

--
BG, SQL Server MVP
www.SolidQualityLearning.com

Join us for the SQL Server 2005 launch at the SQL Week in Israel!
http://www.microsoft.com/israel/sql/sqlweek/default.mspx


[quoted text, click to view]

AddThis Social Bookmark Button