Skip to main content
June 24, 2010
Question

ok i give up on this.

  • June 24, 2010
  • 1 reply
  • 1153 views

i have 2 simple tables

1 - cars

id     make     model

1     toyota     corolla

2 - car_images

rel_car_id     image

1                    front.jpg

1                    back.jpg

i need a 1 line query with the images all in 1 field (comma seperated)

eg

1     toyota     corolla     front,jpg,back.jpg

ive tried complex sql, valuelist function and everything has be beat!

im stuck and woudl love your help.

ps my final goal is to take this new query and dump it to a csv.

This topic has been closed for replies.

1 reply

Participating Frequently
June 25, 2010

Something like this?

SELECT c.make, c.model, i.image

FROM cars c

LEFT JOIN car_images i

ON c.id = i.rel_car_id

WHERE c.id = 1

Ken Ford

Inspiring
June 25, 2010

DECLARE @tmpstr varchar(250) -- or max or whatever

SELECT c.make, c.model, @tmpstr = COALESCE( @tmpstr + ',' , '') + i.image as

'images'

FROM cars c

LEFT JOIN car_images i

ON c.id = i.rel_car_id

WHERE c.id = 1

June 25, 2010

yui8979 thanks,

I am getting close, im am not skilled on this and this looks like a stored procedure?

Where do i put this to run this.

I get an error when i create a new proceduure in SQL 2005 express.

Is there a way I can code this from the coldfusion page?