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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining Table output into one field

Status
Not open for further replies.

Dimm

Programmer
Jun 26, 2001
16
GB
I have an sp that gets product information from a table. I need to join all the results into one string

Example

Name Value Units
Width 35.0 cm
Depth 50.1 cm
Weight 0.75 kg
Height 0.7 cm

Into

Width 35.0 cm | depth 50.1 cm | Weight 0.75 KG | Height 0.7 cm

I guess there is an easy way, but it has me stumped

TIA
 
Does the procedure produce results for a single product or multiple products? For multiple products, you may have to wrap this code in a cursor.

Code:
-- Assumes a single product's data is returned
-- and the sample rows have been selected
-- into the temp table #Measures...

DECLARE @MeasureString varchar(1000)

SELECT @MeasuresString =
       IsNull(@MeasuresString + ' | ', '')
     + Name + ' '
     + Value -- May need to CAST AS varchar
     + Units
FROM #Measures

SELECT @MeasuresString

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Nice one thanks

I learn a litle every day - problem is I forget a lot more!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top