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 2008 Forums
 Transact-SQL (2008)
 select multiple rows in one col as nvarchar

Author  Topic 

mcbulan
Starting Member

7 Posts

Posted - 2011-09-28 : 05:18:17
Hi all,
I am preparing a big query that gathers different values from different tables. You can find the tables and required query below.
Table 1 : students
StudentID Name Surname Class
1 Erica Brown 3
2 Lyn Button 3
3 MichaelMoore 4
...

Table 2 : StudentDetails
StudentID BirthDate BirthPlace Gender Phone email
1 1.1.1991 Place1 F 123 any@any
2 2.2.1992 Place 2 F 234
3 3.3.1993 Place 3 M 345 some@sa
...

Table 3 :
StudentID ExamID Score Date
1 4 AA 13.09.2011
1 5 BA 13.09.2011
1 6 AA 13.09.2011
1 7 CC 13.09.2011
2 5 BA 13.09.2011
2 8 CB 13.09.2011
3 5 AA 13.09.2011
3 6 BB 13.09.2011
...

The desired result of my query :
StudentID Name Surname Gender eMail ExamScore
1 Erica Brown F any@any 4(AA),5(BA),6(AA),7(CC)
2 Lyn Button F 5(BA),8(CB)
3 MichaelMoore M some@sa 5(AA),6(BB)
....

Eventually, i want to combine all exam result in one col for each student row.
Could you please help me to prepare this query?

Thanks for all help.


mcb

mcbulan
Starting Member

7 Posts

Posted - 2011-09-28 : 05:19:49
Please use courier new to display the colunms correctly at the same line :)

mcb
Go to Top of Page

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-09-28 : 07:52:49
refer:

http://sqlyoga.com/2009/02/sql-server-get-comma-separated-list.html

or

http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/

--Ranjit
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-09-28 : 09:17:58
quote:
Originally posted by mcbulan

Please use courier new to display the colunms correctly at the same line :)

mcb


Please use [C0DE] [/C0DE] to show us formatted posts


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-09-28 : 09:35:09
quote:
Originally posted by webfred

Please use [C0DE] [/C0DE] to show us formatted posts



I see what you did there (0 vs o). Tricky...
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-09-28 : 09:38:19
Psst!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mcbulan
Starting Member

7 Posts

Posted - 2011-09-29 : 01:37:31


mcb
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-29 : 03:01:32
"Tricky"

This will cut & paste

mcbulan please modify your query, using the [image]http://snitzimg.sqlteamx.com/icon_edit_topic.gif[/image] on your post) to add these tags around the parts that you want to be Courier New (rather than expecting that each person trying to help you will individually do that for you )

[code]
... Your code here ...
[/code]
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-29 : 03:04:47
"Eventually, i want to combine all exam result in one col for each student row"

You say its a "big query" - what's the maximum number of rows / "grades" that would be combined for a single student? I expect its a "reasonable" number, but if its huge that might be a problem in itself.
Go to Top of Page

mcbulan
Starting Member

7 Posts

Posted - 2011-10-03 : 01:42:14
There will be about 1000 records will be returned. There are about 1000 student records and examination scores will be combined in one cell of its own student record row.

mcb
Go to Top of Page
   

- Advertisement -