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
 SQL Server Development (2000)
 Combining records

Author  Topic 

Incognito
Starting Member

49 Posts

Posted - 2002-01-17 : 03:18:17
I have one table which looks like:

ID, Segment, Data
1 0 Test1
1 1 Test2
1 2 Test3

I want to combine the records so I get:

ID, Data
1 Test1 Test2 Test3

I tried the next: Join, Union, '+' but i couldnt write the right query.
Can someone help me to write it good?

Thnx for your help

Gokhan!


smccreadie
Aged Yak Warrior

505 Posts

Posted - 2002-01-17 : 05:14:05
Something like this will work:

 
DECLARE @data varchar(1000)
SELECT @data = COALESCE(@data + ''''',''''','(''''') +
CAST(RTRIM(data) as varchar(5))+ '' FROM TBL_NAME
SELECT @data = @data + ''''')'



You will need to play with the '''' and possible do some grouping depending on what your data looks like. This is what I use to construct strings to send as pass-though queries to Oracle.



Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-01-17 : 05:31:23
this problem has appeared here before....look for articles on CSV....(you just happen to have "spaces" instead of the comma's as your seperator)


I think there is even A FAQ on it....

Go to Top of Page

Incognito
Starting Member

49 Posts

Posted - 2002-01-17 : 06:44:00
Thnx for the answers.
I checked the CSV "section" but couldnt understood much.
I want to wright a very simple VIEW which gets the records together.
If you can give me more info It would be great.

Thnx

Gokhan

Go to Top of Page

smccreadie
Aged Yak Warrior

505 Posts

Posted - 2002-01-17 : 07:34:14
I'm not sure there's an easy way to do this. Check out http://www.sqlteam.com/item.asp?ItemID=2368.



Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-01-17 : 07:55:58
How about Dynamic Cross tab artilce by Rob(My entry point to Sqlteam .

http://www.sqlteam.com/item.asp?ItemID=2955

HTH

----------------------------------
"True love stories don't have endings."
Go to Top of Page
   

- Advertisement -