Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stumped.. need to concat a string in 4.0.x

Status
Not open for further replies.

Yrrk

IS-IT--Management
Aug 22, 2004
180
US
I have a simple table like this:

Code:
ID int
label varchar

normally a select would look something like:

Code:
1 A
1 B
1 C
2 A
2 B
3 C
4 D
4 E
5 B
5 D

etc.. What i'm trying to do is get select results with the labels on one line like..

Code:
1 A B C
2 A B
3 C
4 D E
5 B D

since this is 4.0.x I can't use the GROUP-CONCAT :(

best i've got so far that doesn't work (only retrieves 1 label per line) is:

Code:
create temporary table B
  select distinct ID, REPEAT(' ',255) as NewLabel
  from A;

update B B1, A A1
  set B1.NewLabel=TRIM(concat(TRIM(B1.NewLabel),' ',A1.label))
  where B1.ID=A1.ID

select *
from B1

Appreciate any thoughts..
 
Typing error, should be

It is much better to handle that in the application then doing it with SQL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top