日期:2014-05-17 浏览次数:20882 次
select wm_concat(to_char(A)||to_char(B)) c1 from t1
------解决方案--------------------
参考:
if object_id('[tb]') is not null drop table [tb]
go
create table [tb] (code int,bill_code nvarchar(6))
insert into [tb]
select 4010305,'001' union all
select 4010305,'005' union all
select 4010306,'007' union all
select 4010307,'009' union all
select 4010305,'003'
if object_id('dbo.f_str')is not null drop function dbo.f_str
go
CREATE FUNCTION dbo.f_str(@code int)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @r varchar(8000)
SET @r = ''
SELECT @r = @r + ',' + bill_code
FROM tb
WHERE code=@code
RETURN STUFF(@r, 1, 1, '')
END
GO
select dbo.f_str(4010305)
/*
001,005,003
(1 個資料列受到影響)
*/