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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-11-08 : 08:22:08
|
| Richard writes "I have a need to create an aggregation fuinction that currently dose not exist in SQL Server 2000.I want this function to be able to concatinate the grouped values of a string column.i.e.create table table1 (code varchar(2),desc varchar(40))insert into table1(code,desc) value ('1','here ')insert into table1(code,desc) value ('1','there ')insert into table1(code,desc) value ('1','everywhere')insert into table1(code,desc) value ('2','this ')insert into table1(code,desc) value ('2','is ')insert into table1(code,desc) value ('2','a ')insert into table1(code,desc) value ('2','test ')if selected normally this would result in code desc----- ----------------------------1 here1 there1 everywhere2 this2 is2 a2 testI want to create the function CONCAT_LIST to be used as follows.Select code, CONCAT_LIST(desc) as descFROM table1GROUP BY codethe resut should be code desc----- -----------1 here there everywhere2 this is a testin triggers there are INSERT and DELETE tables. is there something simmilar for group by's ?help " |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-11-08 : 08:56:00
|
| create function CONCAT_LIST(@id as varchar(2))returns varchar(1000)ASbegindeclare @csv varchar(1000)select @csv = coalesce(@csv+' ','') + desc from table1where code = @idreturn @csvendgo==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|