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.
Author |
Topic |
rekiller
Starting Member
31 Posts |
Posted - 2007-09-25 : 18:38:01
|
I have this registersColumA ColumB0001 AAA0001 BBB0001 CCC0002 DDD0003 XXX0004 ZZZ0004 YYYI want to select and show the follow:ColumA ColumnB0001 AAA,BBB,CCC0002 DDD0003 XXX0004 ZZZ,YYYIs necessary to use cursor and temp table to achieve this? |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-09-25 : 18:42:09
|
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/ |
|
|
rekiller
Starting Member
31 Posts |
Posted - 2007-09-25 : 18:49:23
|
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 |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-25 : 18:59:20
|
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. |
|
|
rekiller
Starting Member
31 Posts |
Posted - 2007-09-25 : 19:09:09
|
Excelent!! That what i wanted!! |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2007-09-26 : 00:30:22
|
Hi,Try This AlsoDeclare @T Table (String varchar(100), Val Varchar(100))Insert into @TSelect 'A',10 union Select 'A', 12 unionselect 'A',14 unionSelect 'B',10 union Select 'B', 12 unionselect 'B',14 select * From @TDeclare @Str1 Varchar(100), @Val Varchar(100)Update @T Set @Val = Val = Case when @Str1 = String then @Val + ', ' + Val Else Val End, @Str1 = StringSelect String ,Max(Val) From @T Group By String |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-26 : 09:01:50
|
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. |
|
|
|
|
|
|
|