SET NOCOUNT ON
DECLARE @i_ID int
DECLARE @s_type varchar(2)
DECLARE @str_type varchar(1000)
DECLARE @tbl1 table
(id int,
str_type varchar(1000) )
Declare cur_id cursor
FOR
SELECT ID FROM test1
GROUP BY ID
ORDER BY ID
OPEN cur_id
FETCH NEXT FROM cur_id INTO @i_ID
WHILE @@FETCH_STATUS = 0
BEGIN
SET @s_type = ''
SET @str_type = ''
DECLARE cur_type cursor
FOR SELECT [TYPE] FROM TEST1
WHERE ID = @i_ID
OPEN cur_type
FETCH NEXT FROM cur_type INTO @s_type
WHILE @@FETCH_STATUS = 0
BEGIN
SET @s_type = @s_type + ','
SET @str_type = @str_type + @s_type
FETCH NEXT FROM cur_type INTO @s_type
END
CLOSE cur_type
DEALLOCATE cur_type
SET @str_type = '''' + LEFT (@str_type, LEN(RTRIM(@str_type))- 1) + ''''
INSERT INTO @tbl1
Values (@i_ID,@str_type)
FETCH NEXT FROM cur_id INTO @i_ID
END
CLOSE cur_id
DEALLOCATE cur_id
SELECT * FROM @tbl1
SET NOCOUNT OFF
DECLARE @i_ID int
DECLARE @s_type varchar(2)
DECLARE @str_type varchar(1000)
DECLARE @tbl1 table
(id int,
str_type varchar(1000) )
Declare cur_id cursor
FOR
SELECT ID FROM test1
GROUP BY ID
ORDER BY ID
OPEN cur_id
FETCH NEXT FROM cur_id INTO @i_ID
WHILE @@FETCH_STATUS = 0
BEGIN
SET @s_type = ''
SET @str_type = ''
DECLARE cur_type cursor
FOR SELECT [TYPE] FROM TEST1
WHERE ID = @i_ID
OPEN cur_type
FETCH NEXT FROM cur_type INTO @s_type
WHILE @@FETCH_STATUS = 0
BEGIN
SET @s_type = @s_type + ','
SET @str_type = @str_type + @s_type
FETCH NEXT FROM cur_type INTO @s_type
END
CLOSE cur_type
DEALLOCATE cur_type
SET @str_type = '''' + LEFT (@str_type, LEN(RTRIM(@str_type))- 1) + ''''
INSERT INTO @tbl1
Values (@i_ID,@str_type)
FETCH NEXT FROM cur_id INTO @i_ID
END
CLOSE cur_id
DEALLOCATE cur_id
SELECT * FROM @tbl1
SET NOCOUNT OFF