SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select grouping fields horizontally
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rekiller
Starting Member

31 Posts

Posted - 09/25/2007 :  18:38:01  Show Profile  Reply with Quote
I have this registers

ColumA ColumB
0001 AAA
0001 BBB
0001 CCC
0002 DDD
0003 XXX
0004 ZZZ
0004 YYY

I want to select and show the follow:

ColumA ColumnB
0001 AAA,BBB,CCC
0002 DDD
0003 XXX
0004 ZZZ,YYY

Is necessary to use cursor and temp table to achieve this?

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 09/25/2007 :  18:42:09  Show Profile  Visit dinakar's Homepage  Reply with Quote
You can write a function that gives you a concatenated list of columnb's for a given ColumnA.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

rekiller
Starting Member

31 Posts

Posted - 09/25/2007 :  18:49:23  Show Profile  Reply with Quote
Ok, so, as i said, i need a function with a cursor moving by columnA registers, and grouping them, in a concataned string??
I dit it that, but i though that was an easier solution
Go to Top of Page

Zoroaster
Aged Yak Warrior

USA
702 Posts

Posted - 09/25/2007 :  18:59:20  Show Profile  Reply with Quote
quote:
Originally posted by rekiller

Ok, so, as i said, i need a function with a cursor moving by columnA registers, and grouping them, in a concataned string??
I dit it that, but i though that was an easier solution



Maybe this will help:

http://www.4guysfromrolla.com/webtech/092105-1.shtml#postadlink






Future guru in the making.
Go to Top of Page

rekiller
Starting Member

31 Posts

Posted - 09/25/2007 :  19:09:09  Show Profile  Reply with Quote
Excelent!! That what i wanted!!
Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 09/26/2007 :  00:30:22  Show Profile  Reply with Quote
Hi,

Try This Also

Declare @T Table (String varchar(100), Val Varchar(100))
Insert into @T
Select 'A',10 union
Select 'A', 12 union
select 'A',14 union
Select 'B',10 union
Select 'B', 12 union
select 'B',14
select * From @T

Declare @Str1 Varchar(100), @Val Varchar(100)

Update @T
Set @Val = Val = Case when @Str1 = String then @Val + ', ' + Val Else Val End, @Str1 = String

Select String ,Max(Val) From @T Group By String

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30218 Posts

Posted - 09/26/2007 :  01:49:30  Show Profile  Visit SwePeso's Homepage  Reply with Quote
This is a SQL Server 2005 forum, right?

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Zoroaster
Aged Yak Warrior

USA
702 Posts

Posted - 09/26/2007 :  09:01:50  Show Profile  Reply with Quote
quote:
Originally posted by Peso

This is a SQL Server 2005 forum, right?

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254



E 12°55'05.25"
N 56°04'39.16"




Thanks for the information Peter, I only knew of the 2000 way of doing it. I have saved this information in my document store!




Future guru in the making.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000