This is my Student table and now we want to print a comma separated list of student names in a grade. our tables record look like this-
1- Aman,Rajan,Ankit 2- Manoj,Vijay,Abott 3- Aman,Akanksha
Grade | StdName
1 | Aman
1 | Rajan
1 | Ankit
2 | Manoj
2 | Vijay
2 | Aboot
3 | Aman
3 | Akanksha

Deepak RawatPosted Jul 7, 2023, 3:35 PM
To print a comma-separated list of student names in a specific grade, you can use SQL query logic. Here's an example query that retrieves the student names for a given grade and formats them as a comma-separated list:
Replace
with the grade for which you want to generate the comma-separated list. This query uses theSTRING_AGGfunction to concatenate theStdNamevalues with commas as the separator.For instance, if you want to retrieve the student names for Grade 1, you would use the following query:
The result of the query will be a single row containing a column named
StudentListthat holds the comma-separated list of student names for the specified grade.Note that the
STRING_AGGfunction may not be available in all database systems. If you're using a different database, consult the documentation for your specific database to find the appropriate function or method for aggregating string values.Amit MohantyPosted Jul 7, 2023, 5:35 AM
Mohamed Azarudeen ZPosted Jul 6, 2023, 1:55 PM
Hi Rajeev
To print a comma-separated list of student names in a specific grade from the given Student table, you can use SQL query syntax. Here's an example query that achieves this:
Replace
[desired_grade]with the grade number you want to retrieve the student names for.For instance, if you want to print the comma-separated list of student names for grade 2, the query will be: