views:

64

answers:

2

I want to display rows as column in SQL Server.

My table looks like this:

images_id  item_id  images_name
-------------------------------
1          1        image1.jpg 
2          1        image2.jpg 
3          1        image3.jpg 
4          2        image4.jpg 
5          2        image5.jpg 
6          2        image6.jpg 

I'd like this output:

images_id  item_id  image1      image2      image3    
------------------------------------------------------
1          1        image1.jpg  image2.jpg  image3.jpg
2          2        image4.jpg  image5.jpg  image6.jpg

Here is an image link.

Is it possible or not? item_id must be dynamically change (not stable).

A: 

This isn't possible without using dynamic SQL. PIVOT requires you to specify the columns still.

Let me know if dynamic SQL is acceptable and I'll spin you an example.

Joel Mansford