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.
Author |
Topic |
foutuguy
Starting Member
3 Posts |
Posted - 2008-01-30 : 05:56:26
|
[code]Hi,I have the following table called "tests" :id WeekNbr name test hours--------------------------------------------------------------------------1 2007/26 John "testA" 52 2007/26 John "testB" 63 2007/26 David "testA" 34 2007/28 David "testC" 25 2007/30 Victor "testD" 1I want to write a query so that I have as a result one row per person and per week, as followedWeekNbr name test hours--------------------------------------------------------------------------------2007/26 John "testA, testB" 112007/26 David "testA" 32007/28 David "testC" 22007/30 Victor "testD" 1This means that I need to concatenate the values of the test column if in the same week and same person.For now, I have only managed to do the job without the test concatenation the following way: SELECT DISTINCT WeekNbr, name, SUM(hours) as [Total of hours]FROM testsGROUP BY WeekNbr, nameand I get the following:WeekNbr name hours-------------------------------------------------------2007/26 John 112007/26 David 32007/28 David 22007/30 Victor 1Anyone could help me please?Thanks so much in advancePierrot[/code] |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-30 : 06:59:09
|
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=trueMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|