:
:
UserID, :
( ):
declare @concattedtext varchar(1000)
SELECT @concattedtext=coalesce(@concattedtext + '|', '') + Value
FROM
SELECT @concattedtext
:
1 | Marius | Fubar
( )
CREATE Table
INSERT into
VALUES (1, 'Test1', 'attr1')
INSERT into
VALUES (1, 'Test2', 'attr2')
INSERT into
VALUES (1, 'Test3', 'attr3')
INSERT into
VALUES (2, 'Test4', 'attr4')
DECLARE @ids TABLE
(
rownum int IDENTITY (1, 1) Primary key NOT NULL,
UserID int
)
DECLARE @out TABLE
(
rownum int IDENTITY (1, 1) Primary key NOT NULL,
UserID int,
ConcatText varchar(1000)
)
INSERT INTO @ids(UserID)
SELECT DISTINCT(UserID) FROM
declare @RowCnt int
declare @MaxRows int
select @RowCnt = 1
select @MaxRows=count(*) from @ids
declare @id int
declare @concattedtext varchar(1000)
while @RowCnt <= @MaxRows
begin
SET @id = 0
SELECT @id=UserID
FROM @ids WHERE rownum=@RowCnt
SET @concattedtext = CONVERT(nvarchar(50), @id)
FROM @ids WHERE rownum=@RowCnt
SELECT @concattedtext=coalesce(@concattedtext + '|', '') + Value
FROM
INSERT INTO @out(UserID, ConcatText)
VALUES (@id, @concattedtext)
Select @RowCnt = @RowCnt + 1
end
SELECT * FROM @out
DROP TABLE
:
rownum|UserID|ConcatTex
1 | 1 |1|attr1|attr2|attr3
2 | 2 |2|attr4
DROP TABLE
.
, . .
.