把id串联起来


/*--------------------------------------------------
Function:把id串联起来
Author:  Robot.H
---------------------------------------------------
*/
SET NOCOUNT ON 
--prepare data
DECLARE @t TABLE(id int )
INSERT INTO @t select 1
UNION ALL      select 2
UNION ALL      select 3
UNION ALL      select 4
--method1
DECLARE @str as varchar(200)
select @str=ISNULL(@str+',','')+CAST(id AS VARCHAR(200)) from @t
PRINT @str
--method2

select @str=
(
select cast(id as varchar(200))+',' 
from @t 
for xml path('')
)
print 
posted @ 2008-11-05 17:19  roboth  阅读(404)  评论(4编辑  收藏  举报