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

Horizontal comma seperated numbers... 1

Status
Not open for further replies.

PLCBeetle

Programmer
Sep 30, 2008
19
US
Hello to all...
I am trying to create a MSSql query that will return a horizontal list of numbers seperated by commas using the code below. I am close but not quite working correctly. Any help will be greatly appreciated. Many thanks :)


DECLARE @pending varchar(500)
SET @pending = ''(SELECT @pending + eco + ', ' FROM mwo.dbo.eco WHERE engineer = 'John Doe')

Result needed like this: 1235, 23423, 66454, 7786, 234, 9276
 
Code:
DECLARE @pending varchar(500)
SELECT @pending = ISNULL(@pending+','  , '') + eco FROM mwo.dbo.eco WHERE engineer = 'John Doe'
SELECT @pending

Borislav Borissov
VFP9 SP2, SQL Server
 
The data type of eco in the database = Int
The query produces the following error...

Server: Msg 245, Level 16, State 1, Line 2
Syntax error converting the varchar value ',' to a column of data type int.
 
Use a CAST on the eco column

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Code:
DECLARE @pending varchar(500)
SELECT @pending = ISNULL(@pending+','  , '') + CAST(eco as varchar(20)) FROM mwo.dbo.eco WHERE engineer = 'John Doe'
SELECT @pending

Borislav Borissov
VFP9 SP2, SQL Server
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top