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 2005 Forums
 Transact-SQL (2005)
 Create a view

Author  Topic 

Rayzak
Starting Member

3 Posts

Posted - 2008-09-11 : 21:08:09
Hello guys.
I'm not sql coder and can't accomplish this task without help.

I have SQL database. And I need to create a view and later on export it to csv.

My output data will look like this:

CODE | NAME | PRICE | STOCK | IMAGE1 | IMAGE2 | IMAGE 3

I used designer and done everytthing except of images. All images stored in one table called IMAGES. I can't reference it same way as I did with price and Brand and Model (via ITEM CODE)

The original IMAGES table have data like:
001 | ITEMCODE2 | IMAGENAME1
002 | ITEMCODE2 | IMAGENAME2
003 | ITEMCODE3 | IMAGENAME3
004 | ITEMCODE5 | IMAGENAME1
004 | ITEMCODE5 | IMAGENAME2
004 | ITEMCODE5 | IMAGENAME3

For example, if I have 5 images for that part number, query will generate me 5 same records with different image names. How can I transform table IMAGES into something like
ITEM_CODE | IMAGE1 | IMAGE2 | IMAGE 3 etc

Thank you for your help.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 21:11:30
check out PIVOT operator

also if you are just creating the CSV, you can use this method
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -