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 |
|
duf
Starting Member
39 Posts |
Posted - 2012-06-06 : 18:46:55
|
| I have loaded .csv file into a table with three columns. In one of the columns are repeated exactly the same data:ID CN OPIS-------------1 123 AAA2 000 eee3 123 BBB4 555 cccIs it possible to combine items 1 and 3 so as to have a one record of the aggregate of: ID CN OPIS-------------1 123 AAA,BBB2 000 eee4 555 ccc |
|
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2012-06-06 : 19:17:53
|
| [code]create table tab(id int ,cn int ,OPIS varchar(20))insert into tab(id,cn,OPIS)select 1,123,'AAA'union all select 2, 000,'eee'union all select 3,123,'BBB'union all select 4,555,'ccc'create function fn (@cn int)returns varchar(max)asbegin declare @str varchar(200)select @str = coalesce(@str+',','')+ opis from tab where cn = @cnreturn @strend select distinct cn ,dbo.fn(cn) as opis from tab[/code]Vijay is here to learn something from you guys. |
 |
|
|
|
|
|
|
|