By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,412 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,412 IT Pros & Developers. It's quick & easy.

question about cursor

P: 44
I have a table like this:

tblProductTag
productID - tag
1 - 'tag1'
1 - 'tag2'
1 - 'tag3'
2 - 'tag1'
2 - 'tag2'

I want to write some SQL that will result in this:

productID - tag
1 - 'tag1, tag2, tag3'
2 - 'tag1, tag2'


What is the best way to achieve this? I was thinking about cursor, but not too sure.
Jul 19 '09 #1
Share this Question
Share on Google+
5 Replies


ck9663
Expert 2.5K+
P: 2,878
Use PIVOT/UNPIVOT

Good luck!!

--- CK
Jul 19 '09 #2

P: 44
But doesn't PIVOT/UNPIVOT require aggregate functions?
Jul 20 '09 #3

ck9663
Expert 2.5K+
P: 2,878
Yes, but you can just use MIN() or MAX()

--- CK
Jul 22 '09 #4

P: 44
What would I do Min or Max on? Im not sorting them, Im just concatenating them with commas.
Jul 22 '09 #5

ck9663
Expert 2.5K+
P: 2,878
You might want to try it first...

Here, read this


Good luck!!!

--- CK
Jul 22 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.