Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sql procedure


sql procedure

Author
Message
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8219 Visits: 14368
All you showed was the SELECT column list. Could you please provide the full query based on the test table I provided in an earlier post? I would like to see how you would get the grouping of the subject IDs for a particular student.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Ed Wagner
Ed Wagner
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10210 Visits: 9539
Now I see the trouble with what you were asking. Does this give you what you're after? It uses a correlated subquery [child] to concatenate the list for each row in [parent]. The [formatted] name is just for formatting it nicely and removing the trailing comma. Since there was no table name in the original post, I used a temporary table named [#test], but you can change it however you like.


SELECT formatted.grade, LEFT(formatted.grade_id_list, LEN(formatted.grade_id_list) - 1)
FROM (SELECT DISTINCT parent.grade, (SELECT CONVERT (Varchar, child.id_grade) + ','
FROM #test child
WHERE child.grade = parent.grade
ORDER BY child.grade
FOR XML PATH ('')) grade_id_list
FROM #test parent) formatted
ORDER BY formatted.grade;



I have no idea if this will work in MySQL at all.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8219 Visits: 14368
Ed Wagner (1/14/2013)
Now I see the trouble with what you were asking. Does this give you what you're after? It uses a correlated subquery [child] to concatenate the list for each row in [parent]. The [formatted] name is just for formatting it nicely and removing the trailing comma. Since there was no table name in the original post, I used a temporary table named [#test], but you can change it however you like.


SELECT formatted.grade, LEFT(formatted.grade_id_list, LEN(formatted.grade_id_list) - 1)
FROM (SELECT DISTINCT parent.grade, (SELECT CONVERT (Varchar, child.id_grade) + ','
FROM #test child
WHERE child.grade = parent.grade
ORDER BY child.grade
FOR XML PATH ('')) grade_id_list
FROM #test parent) formatted
ORDER BY formatted.grade;



I have no idea if this will work in MySQL at all.

Welcome! We are now on the same page.

That is the XML PATH technique I alluded to in my earlier post. It is equivalent to using the SQLCLR object I linked to which attempts to provide a replacement for MySQL's GROUP_CONCAT on SQL Server.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search