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 2000 Forums
 Transact-SQL (2000)
 Record concat display

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-01-22 : 19:10:47
I have the sample data...


select tbl.*
from ( select 1 as a union all
select 2 as a union all
select 3 as a union all
select 4 as a union all
select 5 as a
) as tbl



what i want is to display this in a single column with a delimeter. On the below example, it is delimeted with a minus sign.

select '1-2-3-4-5' as a


Want Philippines to become 1st World COuntry? Go for World War 3...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-22 : 20:43:16
[code]
declare @a varchar(100)

select @a = isnull(@a, '') + convert(varchar(10), a) + '-'
from ( select 1 as a union all
select 2 as a union all
select 3 as a union all
select 4 as a union all
select 5 as a
) as tbl
select @a = left(@a, len(@a) - 1)
select @a as a
[/code]


KH

Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-01-22 : 21:29:10
tnx khtan. is there another way without using a variable?

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-22 : 21:32:17
"is there another way without using a variable?"
What is your considerations ?

Also see here
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx


KH

Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-01-23 : 00:49:31
i know this is a wrong forum to ask. because im trying to do that result set in MySQL. That is why I ask without using a variable. Is it possible?

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-23 : 01:16:13
try posting at www.dbforums.com


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-23 : 01:26:21
Make the concatenation with a UDF.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -